//生成 sha256WithRSA 签名function getSign($content, $privateKey){ $privateKey = "-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($privateKey, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----"; $key = openssl_get_privatekey($privateKey); openssl_sign($content, $signature, $key, "SHA256"); openssl_free_key($key); $sign = base64_encode($signature); return $sign;}//验证 sha256WithRSA 签名function verify($content, $sign, $publicKey){ $publicKey = "-----BEGIN PUBLIC KEY-----\n" . wordwrap($publicKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----"; $key = openssl_get_publickey($publicKey); $ok = openssl_verify($content,base64_decode($sign), $key, 'SHA256'); openssl_free_key($openssl_public_key); return $ok;}
本帖已被设为精华帖!