使用PHP中的RSA加密和解密文本是否有任何PHP 5.3的类,它将使用RSA提供文本加密/解密而无需填充?我有私钥和公钥,p,q和模数。
3 回答
收到一只叮咚
TA贡献1821条经验 获得超4个赞
class MyEncryption{ public $pubkey = '...public key here...'; public $privkey = '...private key here...'; public function encrypt($data) { if (openssl_public_encrypt($data, $encrypted, $this->pubkey)) $data = base64_encode($encrypted); else throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?'); return $data; } public function decrypt($data) { if (openssl_private_decrypt(base64_decode($data), $decrypted, $this->privkey)) $data = $decrypted; else $data = ''; return $data; }}
- 3 回答
- 0 关注
- 792 浏览
添加回答
举报
0/150
提交
取消