生成256位密钥Rijndael在PHP

本文关键字:PHP Rijndael 密钥 256位 生成 | 更新日期: 2023-09-27 18:19:02

下面的代码将成功生成用于加密的KEY。我如何在PHP中使用相同的salt和passkey来重新创建它,以生成一个KEY来解密消息?

public static string GenerateKey(string passkey)
{
    var myAlg = new RijndaelManaged()
    {
         Padding = PaddingMode.PKCS7,
         Mode = CipherMode.CBC,
         KeySize = 256,
         BlockSize = 256,
    };
    byte[] salt = Encoding.ASCII.GetBytes("Some salt value");
    Rfc2898DeriveBytes keys = new Rfc2898DeriveBytes(passkey, salt);
    myAlg.Key = keys.GetBytes(myAlg.KeySize / 8);
    return (Encoding.ASCII.GetString(myAlg.Key));
}

生成256位密钥Rijndael在PHP

检查:http://www.php.net/manual/en/book.mcrypt.php

crypt支持Rijndael-256