英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论