pay/plugins/jdpay/inc/common/RSAUtils.php
2025-11-28 10:08:12 +08:00

19 lines
969 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
class RSAUtils{
public static function encryptByPrivateKey($data) {
$pi_key = openssl_pkey_get_private(file_get_contents(PAY_ROOT.'inc/cert/seller_rsa_private_key.pem'));//这个函数可用来判断私钥是否是可用的可用返回资源id Resource id
$encrypted="";
openssl_private_encrypt($data,$encrypted,$pi_key,OPENSSL_PKCS1_PADDING);//私钥加密
$encrypted = base64_encode($encrypted);//加密后的内容通常含有特殊字符需要编码转换下在网络间通过url传输时要注意base64编码是否是url安全的
return $encrypted;
}
public static function decryptByPublicKey($data) {
$pu_key = openssl_pkey_get_public(file_get_contents(PAY_ROOT.'inc/cert/wy_rsa_public_key.pem'));//这个函数可用来判断公钥是否是可用的可用返回资源id Resource id
$decrypted = "";
$data = base64_decode($data);
openssl_public_decrypt($data,$decrypted,$pu_key);//公钥解密
return $decrypted;
}
}