原始数据:
我爱易语言
易语言签名结果:luvEztvWAkbeN2wSE8rob8yxIAPkBPQzoSnw8VRpxBr5FYS2im4x0/1IsNId0L3utdsJy1RxOlh/0cSINsGk8MevbzTo8nA0sYFqRbqA5ZSBkeETlb/XrnyEzRkzTNdF5Nh3YIO/5mqEvwS6gVOGAhdCfZAzedk08nzrLUstPaM=
变量名 | 类 型 | 静态 | 数组 | 备 注 | 原始数据 | 字节集 | | | 密文 | 字节集 | | | 明文 | 字节集 | | | sign | 文本型 | | | rsa | 整数型 | | | 文本内容 | 文本型 | | | rsa2 | 整数型 | | |
原始数据 = 到字节集 (“我爱易语言”) 调试输出 (“=======================签名=======================”)rsa = PEM_载入私钥 (到文本 (读入文件 (“C:\Users\Administrator\Downloads\config\私钥.pem”)), )sign = RSA签名_sha256 (原始数据, rsa )调试输出 (sign )RSA_释放指针 (rsa )调试输出 (“=======================验证=======================”)rsa2 = PEM_载入公钥 (到文本 (读入文件 (“C:\Users\Administrator\Downloads\config\公钥.pem”)) )调试输出 (RSA验签_sha256 (原始数据, sign, rsa2 )) RSA_释放指针 (rsa2 )调试输出 (“===============================================================”)
PHP签名结果:
mY9EOonAcfUGL6+iDtTVonvYjzTr+uf6FCQwWuZt0H0DpvPApORR51dAZ6uBw4boeWvj4VFfMWErhiuB42aSic5L7fZDj+CKjJXxevOqCU+uJGvMMLoSLLacgUc+QHGEBP8PDCjKAEcQB09+qJdCWsHR5ngau/aE/o6pQL4a90o=
源代码:
- public function SignVerify($data)
- {
- $private_key = file_get_contents(dirname(__FILE__).'/pem/pr.pem');
- $priv_key_id = openssl_get_privatekey($private_key);
- $verify = openssl_sign($data, $signature, $priv_key_id,OPENSSL_ALGO_MD5);
- openssl_free_key($priv_key_id);
- return base64_encode($signature);
- }
- public function CheckSignVerify($data,$sign)
- {
- $signv1 = base64_decode($sign);
- $public_key = file_get_contents(dirname(__FILE__).'/pem/pu.pem');
- $pub_key_id = openssl_get_publickey($public_key);
- $ok = openssl_verify($data, $signv1, $pub_key_id,OPENSSL_ALGO_MD5);
- openssl_free_key($pub_key_id);
- return $ok;
- }
复制代码
PHP 验证签名通过 RSA在线工具针对PHP的签名均可验证通过
RSA在线工具针对易语言的签名均不能验证通过
RSA 公钥:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC3jAFADtPJo5RnQrtcOOg6atGJ
10njxh8MJ9NKEQJ1Te5+cIP1AFxY9Mpm4bYRe3xde29T9GnF9ivm67LzCp64I8mc
uHtqIoZ80zYUhaOiT0aJg3pqu/JUk1dOBdPuG+d+BlgWdz8lu8FZ6bSZj+9PuObF
iOUfLFD3y+sTNqQf8QIDAQAB
-----END PUBLIC KEY-----
RSA 私钥:
-----BEGIN PRIVATE KEY-----
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBALeMAUAO08mjlGdC
u1w46Dpq0YnXSePGHwwn00oRAnVN7n5wg/UAXFj0ymbhthF7fF17b1P0acX2K+br
svMKnrgjyZy4e2oihnzTNhSFo6JPRomDemq78lSTV04F0+4b534GWBZ3PyW7wVnp
tJmP70+45sWI5R8sUPfL6xM2pB/xAgMBAAECgYB1Dyh49zvhPJ9YH/ooPe712sxa
ceChEOkaMogRk7mSoKo7H305EwrSfQRdCxS4H55YbHG7BIU1CORE+Qt+78X7K9Gr
yTWJ9R5ZKviN+T6rPfK5nc1qUMuJCFdseNhcnjmevTkJrGbc9npMCXspnw/EoBm9
mugfDJPgdDrTvUp1sQJBAM8X+p1mDlrLfEWJckv1WoNIAa2hDHQYXqmPiG2tU6Sv
/bCjBFeDxhXlB89UQ2W6fThtvLLJoILv1GUdWvFLlGECQQDHNiCTOCUAwIr9elND
fL4Z4L8VEZHvqc0TIrEyBn8YI412sD/NSHrStz/EOEAsbcOrw6B932/nLOuK5dsv
IM5TAkEArmDyljapP6q4KZViuLMQVBr9zsYdRmR+0SgbKL8Z/0Jxy5p4vXgoA6em
u92oIrC1YB6HFcTRc2+e2MWvHh8WAQJBAMLKr5Gk/bG9lGsFOPOtv2kodVARrSSv
YaLLcn7bEV22LfaXotuFeuweWZDx+/Y1onaLRJywZgijyPI5jliH+JcCQARi2Xmi
G0vIftm8lxwCVfBOvpogcpW7RmZ9W3ICs18KUJ2Ym670OQA/J7pj1js9d8gsycsi
GqfEqmojrOyLTIU=
-----END PRIVATE KEY-----
|