2020.02新版

This commit is contained in:
Blokura
2020-02-21 16:20:55 +08:00
parent 45e2415d71
commit a2f29a310b
755 changed files with 95144 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?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;
}
}