Questions regarding RSADigestSigner and DSAsigner 关于RSADigestSigner和DSAsigner的问题

huangapple go评论65阅读模式
英文:

Questions regarding RSADigestSigner and DSAsigner

问题

I am new to Bouncy Castle. I have some questions regarding the signers package in Bouncy Castle. For RSADigestSigner, is our message hashed internally or do we have to hash it on our own? Another similar question is for DSASigner, it does not have a built-in digest, so do we have to pre-hash our message before using DSASigner?

Here are two of my codes:

 // RSADigestSigner

        // Pick the hash, SHA512 in this case
        SHA512Digest digest = new SHA512Digest();

        // Create an RSADigestSigner to sign
        RSADigestSigner sign = new RSADigestSigner(digest);

        // Initialize for signing
        sign.init(true, privKey);

        // Pass data to sign
        sign.update(bytes, 0, bytes.length);

        // Generate the signature
        try {
            signature = sign.generateSignature();
        } catch (DataLengthException | CryptoException e) {
            e.printStackTrace();
        }
// Create a DSASigner to sign 
		DSASigner sign = new DSASigner();
		
		// Initialize DSASigner
		sign.init(true, privKey);
		
		// Hash the message
		
		
		// Generate the signature
		signature = sign.generateSignature(input);
英文:

I am new to Bouncy castle. I have some questions regarding signers package in bouncy castle. For RSADigestSigner, is our message hashed internally or do we have to hash it on our own? Another similiar question is for DSASigner, it does not have a built-in digest, so do we have to pre-hash our message before using DSASigner?

Here are two of my codes:

 // RSADigestSigner

        // Pick the hash, SHA512 in this case
        SHA512Digest digest = new SHA512Digest();

        // Create a RSADigestSigner to sign
        RSADigestSigner sign = new RSADigestSigner(digest);

        // Initialize for signing
        sign.init(true, privKey);

        // Pass data to sign
        sign.update(bytes, 0, bytes.length);

        // Generate the signature
        try {
            signature = sign.generateSignature();
        } catch (DataLengthException | CryptoException e) {
            e.printStackTrace();
        }
// Create a DSASigner to sign 
		DSASigner sign = new DSASigner();
		
		// Initialize DSASigner
		sign.init(true, privKey);
		
		// Hash the message
		
		
		// Generate the signature
		signature = sign.generateSignature(input);

答案1

得分: 1

对于 DSASigner,您必须自行计算哈希值,而对于 RSADigestSigner,哈希值是在类内部计算的。这是可能的,因为 RSADigestSigner 的构造函数接受一个 Digest 参数。但与 RSADigestSigner 对应的是 DSADigestSigner,而不是 DSASigner,因此您可能想使用 DSADigestSigner

英文:

For DSASigner you must compute the hash yourself, whereas for RSADigestSigner the hash is computed internally to the class. This is possible because the constructor for RSADigestSigner takes a Digest argument. But the parallel to RSADigestSigner is DSADigestSigner, not DSASigner, so you probably want to use DSADigestSigner.

huangapple
  • 本文由 发表于 2023年5月30日 06:02:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76360535.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定