echo "<strong>Hashing</strong><br />"; $password = '******'; // user generated password $salt = openssl_random_pseudo_bytes(24); echo "Salt= {$salt}<br />"; $md5 = md5($password . $salt); echo "MD5 = {$md5}<br />"; $sha1 = sha1($password . $salt); echo "SHA1 = {$sha1}<br />"; $sha512 = hash('sha512', $password . $salt); echo "SHA512 = {$sha512}<br />"; echo "<br />-----------------------------------------<br />"; echo "<strong>Encryption</strong><br />"; $secretstring = "This is the secret string I want encrypting"; echo "Secret String = {$secretstring} <br />"; $encrypted_txt = public_encrypt($secretstring); echo "Encrypted Text = {$encrypted_txt} <br />"; $decrypted_txt = private_decrypt($encrypted_txt); echo "Decrypted Text = {$decrypted_txt} <br />"; echo "DECRYPTION "; if ($secretstring === $decrypted_txt) { echo "WORKED"; } else { echo "FAILED"; } function public_encrypt($plaintext) { $fp = fopen("./mykey.pub", "r"); $pub_key = fread($fp, 8192); fclose($fp); openssl_get_publickey($pub_key);
'; //208 characters, which is the up range my key can work with. Beyond that, it doesnot work. //I use 2048 bit key, so it can enctry no more than 2048/8=256 byte data. /* <education> humber </education> </resume> '; */ $encrypted = public_encrypt($str); echo $encrypted; echo "<br>"; echo private_decrypt($encrypted); function public_encrypt($plaintext) { $fp = fopen("publickey", "r"); $pub_key = fread($fp, 8192); fclose($fp); openssl_get_publickey($pub_key); openssl_public_encrypt($plaintext, $crypttext, $pub_key); return base64_encode($crypttext); } function private_decrypt($encryptedext) { $fp = fopen("privatekey", "r");