I have this WinRT code:
public static string Encrypt(string Login)
{
var input = CryptographicBuffer.ConvertStringToBinary(Login, BinaryStringEncoding.Utf8);
var BinKey = CryptographicBuffer.ConvertStringToBinary(Key, BinaryStringEncoding.Utf8);
var BinIV = CryptographicBuffer.ConvertStringToBinary(IV, BinaryStringEncoding.Utf8);
var Encryptor = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var SymmKey = Encryptor.CreateSymmetricKey(BinKey);
var encrypted = CryptographicEngine.Encrypt(SymmKey, input, BinIV);
return CryptographicBuffer.EncodeToBase64String(encrypted);
}
public static string Decrypt(string LoginToDecode)
{
var input = CryptographicBuffer.DecodeFromBase64String(LoginToDecode);
var BinKey = CryptographicBuffer.ConvertStringToBinary(Key, BinaryStringEncoding.Utf8);
var BinIV = CryptographicBuffer.ConvertStringToBinary(IV, BinaryStringEncoding.Utf8);
var Decryptor = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7);
var SymmKey = Decryptor.CreateSymmetricKey(BinKey);
var Decrypted = CryptographicEngine.Decrypt(SymmKey, input, BinIV);
return CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, Decrypted);
}
and I need this in PHP. I'm trying do this in this code but this isn't the same:
function decryptRJ256($key,$iv,$string_to_decrypt){
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\0\4");
return($rtn);}
function encryptRJ256($key,$iv,$string_to_encrypt){ $rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv); $rtn = base64_encode($rtn); return($rtn);}
For example for this input in c#:
- Key = "lkirwf897+22#bbt"
- IV = "741952hheeyy66#c"
- password = "Asd"
I have "eSy8m8ygN7rtC80DMdGOUQ==". I need this in PHP.