Page 1 of 1

Which can I choose for digital signature, Cipher.MODE_ENCRYPT or Cipher.MODE_DECRYPT?

Posted: Mon Mar 21, 2016 4:04 am
by cprgolds
I have used this code line to initialize RSA cipher.

Code: Select all

 crypto.rsaCipher.init(keyStore.cardPrivateKey, Cipher.MODE_DECRYPT);


which is initialized as:

Code: Select all

rsaCipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false);


Now my question is I am not sure which parameter to select between Cipher.MODE_ENCRYPT and Cipher.MODE_DECRYPT to generate digital signature. Any one knows? Pls help! Any comment is appreciated.

Re: Which can I choose for digital signature, Cipher.MODE_ENCRYPT or Cipher.MODE_DECRYPT?

Posted: Tue Mar 22, 2016 2:22 am
by lostsiwonlw
Signature.MODE_SIGN

Re: Which can I choose for digital signature, Cipher.MODE_ENCRYPT or Cipher.MODE_DECRYPT?

Posted: Tue Mar 22, 2016 2:28 am
by choimillen
Signature.MODE_SIGN


Using Signature.MODE_SIGN is incorrect, just in my opinion.

Re: Which can I choose for digital signature, Cipher.MODE_ENCRYPT or Cipher.MODE_DECRYPT?

Posted: Tue Mar 22, 2016 3:22 am
by mabel
Both Cipher.MODE_DECRYPT and Signature.MODE_SIGN work for you.

The reason is simply that Cipher.MODE_DECRYPT and Signature.MODE_SIGN both have the same integer value: 2