Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

Hash signing

JavaCard Applet Development Related Questions and Answers.
AndrewS
Posts: 2
Joined: Mon Feb 22, 2016 2:36 pm
Points :204
Contact:

Hash signing

Post by AndrewS » Fri Apr 08, 2016 12:24 am

Hello,
Is there an easy way to sign a hash in order to produce a PKCS #1 signature? I'm asking because the Signature class automatically hashes the input. I want to sign the documents, and can not send files to the card due to the limited amount of memory
Sending the data in portions to the smartcard for signing is ineffective. Sending only the hash seems to be the only solution, but unfortunately, the Java Card Standard doesn't support it
One solution could be to create the PKCS #1 signature structure by hand (RFC2313) and encrypt it with the private key. I guess ALG_RSA_NOPAD must be used for the latter. But how do it I don't know.

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: Hash signing

Post by mabel » Fri Apr 08, 2016 2:09 am

AndrewS wrote:Hello,
Is there an easy way to sign a hash in order to produce a PKCS #1 signature? I'm asking because the Signature class automatically hashes the input. I want to sign the documents, and can not send files to the card due to the limited amount of memory
Sending the data in portions to the smartcard for signing is ineffective. Sending only the hash seems to be the only solution, but unfortunately, the Java Card Standard doesn't support it
One solution could be to create the PKCS #1 signature structure by hand (RFC2313) and encrypt it with the private key. I guess ALG_RSA_NOPAD must be used for the latter. But how do it I don't know.

You can get a java card that supports java card 3.0.4
Then use this method
short signPreComputedHash(byte[] hashBuff, short hashOff, short hashLength, byte[] sigBuff, short sigOffset)

to generate the signature of the pre-computed hash data.

Here is the details about this function described in Java CardTM application programming interface (API), Version 3.0.4, Classic Edition.
signPreComputedHash
public abstract short signPreComputedHash(byte[] hashBuff,
short hashOff,
short hashLength,
byte[] sigBuff,
short sigOffset)
throws CryptoExceptionGenerates the signature of the precomputed hash data.
A call to this method also resets this Signature object to the state it was in when previously initialized via a call to init(). That is, the object is reset and available to sign another precomputed hash.

Note:
This method throws an exception if the underlying signature algorithm does not compute a distinct message digest value prior to applying cryptographic primitives. These algorithms throw exception - DES, triple DES, AES, and KOREAN SEED.
Any data previously accumulated from previous calls to the update method are discarded.
The hash and output buffer data may overlap.

Parameters:
hashBuff - the input buffer of precomputed hash to be signed
hashOffset - the offset into the buffer where the hash begins
hashLength - the byte length of the hash
sigBuff - the output buffer to store signature data
sigOffset - the offset into sigBuff at which to begin signature data

Returns:
number of bytes of signature output in sigBuff

Throws:
CryptoException - with the following reason codes:
CryptoException.UNINITIALIZED_KEY if key not initialized.
CryptoException.INVALID_INIT if this Signature object is not initialized or initialized for signature verify mode.
CryptoException.ILLEGAL_USE if one of the following conditions is met:
if the hashLength value is not equal to the length of the algorithm's message digest length.
if this Signature algorithm includes message recovery functionality.
if the Signature algorithm does not compute a distinct message digest value prior to applying cryptographic primitives

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 64 guests

JavaCard OS : Disclaimer