2

I am trying to initialize a Mac instance using an empty key. But it is failing with "InvalidKeyException". Following is the snippet of code working with Oracle Java, but giving exception with IBM J9. . Can someone please help me in resolving the problem?

import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException;

import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec;

public class TestHM {

 public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {

     String alg = "HmacSHA256";

     Mac m = Mac.getInstance(alg);

     SecretKeySpec secretKey = new SecretKeySpec(new byte[] {0}, 1, 0, alg);

     m.init(secretKey);

     System.out.println("End");
 }

} Current output: Exception in thread "main" java.security.InvalidKeyException: Missing key data at com.ibm.crypto.provider.HmacSHA256.engineInit(Unknown Source) at javax.crypto.Mac.a(Unknown Source) at javax.crypto.Mac.init(Unknown Source) at TestHM.main(TestHM.java:18)

Java Version: java -version java version "1.8.0" Java(TM) SE Runtime Environment (build pap6480sr3fp10-20160720_02(SR3fp10)) IBM J9 VM (build 2.8, JRE 1.8.0 AIX ppc64-64 Compressed References 20160719_312156 (JIT enabled, AOT enabled) J9VM - R28_Java8_SR3_20160719_1144_B312156 JIT - tr.r14.java_20160629_120284.01 GC - R28_Java8_SR3_20160719_1144_B312156_CMPRSS J9CL - 20160719_312156) JCL - 20160719_01 based on Oracle jdk8u101-b13

  • Maybe it doesn't work with 'zero-key'. – Lorinczy Zsigmond Nov 08 '18 at 19:34
  • Thanks for your response. Mostly you are correct. But I wanted to understand why it fails with IBM J9 and not with oracle jvm. I have tried to see if there are any differences documented, but could not find anything. So, it would be helpful if I can get reference for this behavior documented ? or else any idea about how to debug the root cause for the difference in behavior ? – ramakrushna mishra Nov 09 '18 at 05:17
  • Basically, they are two different implementations of the same specification; they might very well differ in edge cases. – Lorinczy Zsigmond Nov 09 '18 at 05:56

0 Answers0