Jay*_*cee 1 java encryption sha1 rsa digital-signature
无辜地,我认为"SHA1withRSA算法"只是用"SHA1"操作plainText,并使用RSA/pkcs1padding来加密"SHA1"的结果.但是,我发现我错了,直到我写了一些java代码来测试我的想法.我使用RSA publickey来解密签名,我使用相应的私钥来签署"SHA1withRSA算法".但我发现结果不等于"SHA1(plainText)",下面是我的java代码:
String plaintext= "123456";
Signature signature=Signature.getInstance("SHA1withRSA",new BouncyCastleProvider());
signature.initSign(pemPrivatekey);
signature.update(plaintext.getBytes());
byte[] sign = signature.sign();
//RSA decode
byte[] bytes = RsaCipher.decryptByRsa(sign, pemPublickey);
String rsaDecodeHex=Hex.toHexString(bytes);
System.out.println(rsaDecodeHex.toLowerCase());
String sha1Hex = Hash.getSha1(plaintext.getBytes());
System.out.println(sha1Hex);
//rsaDecodeHex!=sha1Hex
Run Code Online (Sandbox Code Playgroud)
很容易找到rsaDecodeHex!=sha1Hex,在哪里
rsaDecodeHex = 3021300906052b0e03021a050004147c4a8d09ca3762af61e59520943dc26494f8941b
和
sha1Hex = 7c4a8d09ca3762af61e59520943dc26494f8941b.
那么,"SHA1withRSA"的细节是什么?
PCKS#1 v15中定义的数字签名算法对摘要算法标识符和ASN.1中编码的消息的摘要进行RSA加密.
signature =
RSA_Encryption(
ASN.1(DigestAlgorithmIdentifier + SHA1(message) ))
Run Code Online (Sandbox Code Playgroud)
见(RFC2313)
10.1签名过程
签名过程包括四个步骤:消息摘要,数据编码,RSA加密和八位字符串到位串转换.签名过程的输入应为八位字符串M,即消息; 和签名者的私钥.签名过程的输出应为比特串S,即签名.
所以你rsaDecodeHex包含算法标识符和SHA1摘要plainText
| 归档时间: |
|
| 查看次数: |
7441 次 |
| 最近记录: |