phpRSA加密解密函数
使用方法:
加密
$txt="ytecn"; $pubkey="公钥" $macdata = RSAEncrypt::encrypt($txt, $pubkey);
解密
$txt="ytecn"; $pubkey="私钥" $macdata = RSAEncrypt::decrypt($txt, $pubkey);
类文件
class RSAEncrypt { public static function encrypt($str, $publicKey) { $pubKey = openssl_pkey_get_public($publicKey); openssl_public_encrypt($str, $outStr, $pubKey); return base64_encode($outStr); } public static function decrypt($str, $privateKey) { $inputByte = base64_decode($str); $decoded = base64_decode($privateKey); $priKey = openssl_pkey_get_private($decoded); openssl_private_decrypt($inputByte, $outStr, $priKey); return $outStr; } }