Generate HMAC_SHA256 signature in JavaCard applet
09:00 07 Nov 2012

I am trying to sign a message which contains in inBuffer byte array using my own derived key S (also byte array). The snippet of the function from javacard (jc) applet module is given below. I am using javacard2.2.2 library for developing jc applet. I am using Android application for sending process request.

I am receiving return code '6A81' which means 'function not supported'. Now, I don't know how to proceed as I failed to understand that it is mentioning about HMAC_SHA256 not supported or I am making some mistake in the function.

    Signature m_sessionMAC = null;
    HMACKey keyType = null;
    Sign = new byte[64];

    bytesRead = apdu.setIncomingAndReceive();

    // Create HMAC Key Used in Mac
    m_sessionMAC = Signature.getInstance(Signature.ALG_HMAC_SHA_256, false);

    // Create HMAC Key Used in Mac
    keyType = (HMACKey) KeyBuilder.buildKey(KeyBuilder.TYPE_HMAC, KeyBuilder.LENGTH_HMAC_SHA_256_BLOCK_64, false); 
    keyType.setKey(S,(short) 0, (short) S.length);
    m_sessionMAC.init(keyType, Signature.MODE_SIGN);

    //Generate Signature on inBuffer (received data to sign)
    echoOffset = m_sessionMAC.sign(inBuffer, ISO7816.OFFSET_CDATA, ISO7816.OFFSET_LC, Sign , (short)0); 
    Util.arrayCopyNonAtomic(Sign, ( short ) 0, inBuffer, ( short ) 0, echoOffset); 
    apdu.setOutgoingAndSend( ( short ) 0, (short) echoOffset );

How can I implement HMAC_SHA256 or HMAC_SHA1 symmetric crypto in javacard applet?

digital-signature smartcard javacard symmetric-key