当我使用 AES 256 加密它们时,RSA(私有和公共)的密钥对具有相同的密文是否正常?
事实上,我正在使用 PHP:
<?php
$key="abc";
$config = array(
"digest_alg" => "sha512",
"private_key_bits" => 4096,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
// Create the private and public key
$res = openssl_pkey_new($config);
// Extract the private key from $res to $privKey
openssl_pkey_export($res, $privKey);
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey= $pubKey["key"];
aes256Key = hash("SHA256", $password, true);
// for good entropy (for MCRYPT_RAND)
srand((double) microtime() * 1000000);
// generate random iv
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND);
$crypted_priv= rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $privKey, MCRYPT_MODE_CBC, $iv)), "\0\3");
$crypted_pub= rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $pubKey, MCRYPT_MODE_CBC, $iv)), "\0\3");
?>
更新:我用 CBC 替换了 ECB,希望它是正确的......