我一直在尝试在 PHP 中设置一个简单的 openssl_seal 和 openssl_open 脚本(8.0.8 是我安装的版本),我没有收到任何错误,但 openssl_open 总是返回 FALSE。
如果我做错了什么,谁能告诉我?
$algo = 'aes-256-gcm';
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($algo));
$data = "Data to Seal";
$res = openssl_pkey_new(array(
'digest_alg' => 'sha256',
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA
));
openssl_pkey_export($res, $privkey);
$pubkey = openssl_pkey_get_details($res);
$pubkey = $pubkey["key"];
openssl_seal($data, $sealed, $envelope, array($pubkey), $algo, $iv);
$openKey = openssl_pkey_get_private($privkey);
if (openssl_open($sealed, $open, $envelope[0], $openKey, $algo, $iv)) {
echo "OPENED: ".$open;
} else {
echo "Failed to open Data!";
}