gpt4 book ai didi

c# - 使用 Rijndael 解密时 C# 和 PHP 中的不同结果

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:05 25 4
gpt4 key购买 nike

<分区>

下面是我的 C# 代码,它用 C# 解密编码的字符串。

RijndaelManaged RijndaelCipher = new RijndaelManaged(); 
string DecryptedData;
byte[] EncryptedData = Convert.FromBase64String(TextToBeDecrypted);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
//Making of the key for decryption
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
//Creates a symmetric Rijndael decryptor object.
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
byte[] plainText = Decryptor.TransformFinalBlock(EncryptedData, 0, EncryptedData.Length);

//Converting to string
DecryptedData = Encoding.Unicode.GetString(plainText);

但我想要上面相同的 PHP 代码。我尝试了下面的代码,但它没有给我正确的输出。

function Decrypt( $encrypted, $key, $iv ){
$encrypted=base64_decode($encrypted);
return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_CFB, $iv);
}

这里我得到输出 $)íqyZiG¤õ¡ (相同,在 C# 中加密时使用)。

我应该将什么传递给 $iv 以便获得解密输出“Snehal”?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com