繁体   English   中英

“ SHA1withRSA”的详细信息是什么?

[英]What's the detail in “SHA1withRSA”?

天真地,我以为“ SHA1withRSA algorithm”只是用“ SHA1”来操作plainText,然后使用RSA / pkcs1padding来加密“ SHA1”的结果。但是,直到写了一些Java代码来测试我的想法后,我才发现自己是错的。 我使用RSA公钥来解密签名,然后使用“ 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

容易找到rsaDecodeHex!=sha1Hex ,其中

rsaDecodeHex = 3021300906052b0e03021a050004147c4a8d09ca3762af61e59520943dc26494f8941b

sha1Hex = 7c4a8d09ca3762af61e59520943dc26494f8941b。

那么,“ SHA1withRSA”中的细节是什么?

PCKS#1 v15中定义的数字签名算法对摘要算法标识符和ASN.1中编码的消息摘要进行RSA加密。

signature = 
    RSA_Encryption( 
      ASN.1(DigestAlgorithmIdentifier  + SHA1(message) )) 

参见( RFC2313

10.1签名过程

签名过程包括四个步骤:消息摘要,数据编码,RSA加密和八位字节字符串到位字符串的转换。 签名过程的输入应该是一个八位字节串M,即消息; 和签名者的私钥。 签名过程的输出应为比特串S,即签名。

因此,您的rsaDecodeHex包含算法标识符和plainText的SHA1摘要

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM