Page 1 of 1

Card throws an exception thrown when loading the signature on the card

Posted: Mon Dec 28, 2015 11:53 pm
by Riddle
I try to load the signature on the card which is a 64 bytes RSA SHA1 signature.

Here is section of my apple.

Code: Select all

RSAPrivateKey  rsa_PrivateKey;
RSAPublicKey rsa_PublicKey;
KeyPair rsa_KeyPair;
Cipher cipherRSA;
Signature sig;
short expo;
short PIN;
byte[] pinSig = new byte[64];

public short verify (byte[] pin){

    sig = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false);
    sig.init(rsa_PublicKey, Signature.MODE_VERIFY);
    if( sig.verify(pin, (short)0, (short)pin.length, pinSig, (short)0, (short)pinSig.length)){
        return 1;
    }else{
        return 0;
    }
}

public void setpinSig( byte[] sig){


    pinSig = sig;
}

public void setPIN(short pin){

    PIN = pin;

}

public short isPIN(short pin){

    if ( pin != PIN )return 0;

    return 1;

}


When I called setpinSig method, I got an exception thrown on card. I don't know how to fix this problem.
Could anyone help me out?
checkFieldStore -> Security exception
throw_error(SECURITY_EXCEPTION)

Re: Card throws an exception thrown when loading the signature on the card

Posted: Thu Dec 31, 2015 1:34 am
by mabel
If the pinSig value is always 64 bytes long, you should use the following implementation.

Code: Select all

public void setpinSig( byte[] sig)
{
        javacard.framework.Util.arrayCopy(sig, (short) 0,
        pinSig, (short) 0, (short) 64);
}