openssl_decrypt(..) works with most but not all method types.
This list can vary, depending on the data (Message) and key (Password) used.
See the following code and edit the $text and $password values.
Code checks if text is the same after encrypting then decrypting it.
Note:
You can still use openssl_encrypt(..) with;
User enters 'Log-in password'
(Encrypted and stored using openssl_encrypt)
Next time.
User logs-in with 'Log-in password'
(Check that encrypted 'Log-in password' = stored data)
<CODE>
// Please edit $password=... and $text=...
$password = "This is a journey into sound";
$text = "";
for($charNo=0; $charNo<=255; $charNo=$charNo+1){
// if($charNo==127) {$charNo=$charNo+1;}
if(!$charNo<127){
// $text = $text."&#x".strtoupper(dechex($charNo)).";";
$text = $text.chr($charNo);
} else {
$text = $text.chr($charNo);
}
}
$text = "This is a test message.";
print "<TABLE BORDER=\"1\">\n";
print "<TR><TD><B>Encryption type:</B></TD><TD><B>String after converting back:</B></TD></TR>\n";
$ciphers = openssl_get_cipher_methods();
for($pointer=0; $pointer<count($ciphers); $pointer=$pointer+1){
$edit = EncryptDecrypt($text, true, $password, $ciphers[$pointer]);
$check = EncryptDecrypt($edit, false, $password, $ciphers[$pointer]);
if($text!=$check){
$info = $check;
print "<TR><TD>".$ciphers[$pointer]."</TD><TD>".$info."</TD></TR>\n";
}
}
print "</TABLE>\n";
function EncryptDecrypt($oldText, $encryptIt=true, $password="PASSWORD", $encryptType=""){
$ciphers = openssl_get_cipher_methods();
$foundEncType = false;
for($pointer=0; $pointer<count($ciphers); $pointer=$pointer+1){
if($ciphers[$pointer]==$encryptType){$foundEncType=true;}
}
if(!$foundEncType){
$encryptType = "RC2-64-CBC"; // Default value used if not set or listed.
}
if($encryptIt){
$newText = openssl_encrypt($oldText,$encryptType,$password);
} else {
$newText = openssl_decrypt($oldText,$encryptType,$password);
}
return $newText;
}
</CODE>
The following (sometimes) don't work:
DES-EDE3-CFB1 (sometimes)
aes-128-gcm
aes-192-gcm
aes-256-gcm
des-ede3-cfb1 (sometimes)
id-aes128-GCM
id-aes192-GCM
id-aes256-GCM