$r = openssl_public_decrypt($crypted, $decrypted, $this->_pubKey); if ($r) { return $decrypted; } return null; } public function __destruct() { @fclose($this->_privKey); @fclose($this->_pubKey); } } //以下是一个简单的测试demo,如果不需要请删除 $rsa = new Rsa('sslkey'); //sslkey为存放密钥的路径,将已有的密钥文件复制到该路径下,公钥名称为pub.key,私钥名称为priv.key //$rsa->createKey(); //创建一对密钥,如果密钥对已经存在,不需调用 //私钥加密,公钥解密 echo 'source:我是老鳖<br />'; $pre = $rsa->privEncrypt("我是老鳖"); echo 'private encrypted:<br />' . $pre . '<br />'; $pud = $rsa->pubDecrypt($pre); echo 'public decrypted:' . $pud . '<br />'; //公钥加密,私钥解密 echo 'source:干IT的<br />'; $pue = $rsa->pubEncrypt('干IT的'); echo 'public encrypt:<br />' . $pue . '<br />'; $prd = $rsa->privDecrypt($pue); echo 'private decrypt:' . $prd; $p = "BHh8quzSlewEJQ6ZiYOsBRDxUVcSh+fVboVI0YXK2LJNH9v/PRG4VpbmroiJtn9Gp55kVAVHLBgTCwnrd0N2FJE+0M5+n6TzkOul1tSgzo+WZVJWXOFlw0S3m8LMLP0ZtMrfQxj8JtgNbewoFIQ2M3ReYCpLTQ4D1EwxzwT/b88="; $prd = $rsa->privDecrypt($p); echo "???????" . $prd;