【发布时间】:2021-12-05 06:10:13
【问题描述】:
嗨,我在使用 PHP 以上的私钥解密 RSA 时遇到错误,请帮忙 (我尝试在 c# 私钥上解密工作正常)
错误
error:04065072:rsa routines:rsa_ossl_private_decrypt:padding check failed
PHP
class RSA{
protected $private;
public function __construct()
{
$this->private = @file_get_contents("private.pem");
}
public function decrypt($data)
{
if (is_null($data) || empty($data) || is_string($data) === false) {
throw new RuntimeException('Needless to encrypt.');
} elseif (is_null($this->private) || empty($this->private)) {
throw new RuntimeException('You need to set the private key.');
}
$key = openssl_get_privatekey($this->private);
if (!openssl_private_decrypt(base64_decode($data), $result, $key)){
throw new Exception(openssl_error_string());
}
return $result;
}
}
【问题讨论】:
-
将此部分分成问题和答案。然后人们就会知道在哪里寻找答案