12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- function rsaSign($data, $private_key_path) {
- $priKey = file_get_contents($private_key_path);
- $res = openssl_get_privatekey($priKey);
- openssl_sign($data, $sign, $res);
- openssl_free_key($res);
-
- $sign = base64_encode($sign);
- return $sign;
- }
- function rsaVerify($data, $ali_public_key_path, $sign) {
- $pubKey = file_get_contents($ali_public_key_path);
- $res = openssl_get_publickey($pubKey);
- $result = (bool)openssl_verify($data, base64_decode($sign), $res);
- openssl_free_key($res);
- return $result;
- }
- function rsaDecrypt($content, $private_key_path) {
- $priKey = file_get_contents($private_key_path);
- $res = openssl_get_privatekey($priKey);
-
- $content = base64_decode($content);
-
- $result = '';
- for($i = 0; $i < strlen($content)/128; $i++ ) {
- $data = substr($content, $i * 128, 128);
- openssl_private_decrypt($data, $decrypt, $res);
- $result .= $decrypt;
- }
- openssl_free_key($res);
- return $result;
- }
- ?>
|