Skip to Main Content

Java Card

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HMAC_SHA_256

madhushree gcJul 16 2025 — edited Jul 16 2025

I am not able to execute the below code snippet in the oracle java card simulator . Please help me in identifying the issue. I am getting the error code 1.

public void initHMAC() {
  try {

Signature _hmac = Signature.getInstance(MessageDigest.ALG_SHA_256, Signature.SIG_CIPHER_HMAC, Cipher.PAD_NULL, false);
    byte[] _key = JCSystem.makeTransientByteArray(32, JCSystem.CLEAR_ON_DESELECT);
     byte[] input = {
         61, 83, -62, 42, 33, -51, -86, 108, 97, 102, -58, 83, -127, 92, 18, 127,
         -15, -8, 84, 49, -10, -25, 47, -121, -72, -2, 61, -62, 11, -7, -86, 80,
         -105, -81, 1, -68, -89, 12, -89, -18, -1, -14, -51, 111, 101, -8, -10, 58
        };

Util.arrayCopy(input, 0, _key, (short) 0, 32);
    if (_algorithm == Signature.ALG_HMAC_SHA_256) {
      HMACKey hk = (HMACKey) KeyBuilder.buildKey(KeyBuilder.TYPE_HMAC_TRANSIENT_RESET,KeyBuilder.LENGTH_HMAC_SHA_256_BLOCK_64, false);

hk.setKey(_key, (short)0, (short)32);
      _hmac.init(hk, Signature.MODE_SIGN);

} else
      //

} catch (Exception e) {
    //
  }
}

This post has been answered by Gabriel Serban-Oracle on Jul 17 2025
Jump to Answer
Comments
Post Details
Added on Jul 16 2025
2 comments
97 views