InvalidKeyException from Mac.init() when used with empty key on IBM J9











up vote
1
down vote

favorite












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










share|improve this question






















  • Maybe it doesn't work with 'zero-key'.
    – Lorinczy Zsigmond
    Nov 8 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 9 at 5:17










  • Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
    – Lorinczy Zsigmond
    Nov 9 at 5:56















up vote
1
down vote

favorite












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










share|improve this question






















  • Maybe it doesn't work with 'zero-key'.
    – Lorinczy Zsigmond
    Nov 8 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 9 at 5:17










  • Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
    – Lorinczy Zsigmond
    Nov 9 at 5:56













up vote
1
down vote

favorite









up vote
1
down vote

favorite











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










share|improve this question













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







hmac j9






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 12:54









ramakrushna mishra

162




162












  • Maybe it doesn't work with 'zero-key'.
    – Lorinczy Zsigmond
    Nov 8 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 9 at 5:17










  • Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
    – Lorinczy Zsigmond
    Nov 9 at 5:56


















  • Maybe it doesn't work with 'zero-key'.
    – Lorinczy Zsigmond
    Nov 8 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 9 at 5:17










  • Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
    – Lorinczy Zsigmond
    Nov 9 at 5:56
















Maybe it doesn't work with 'zero-key'.
– Lorinczy Zsigmond
Nov 8 at 19:34




Maybe it doesn't work with 'zero-key'.
– Lorinczy Zsigmond
Nov 8 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 9 at 5:17




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 9 at 5:17












Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
– Lorinczy Zsigmond
Nov 9 at 5:56




Basically, they are two different implementations of the same specification; they might very well differ in edge cases.
– Lorinczy Zsigmond
Nov 9 at 5:56

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208183%2finvalidkeyexception-from-mac-init-when-used-with-empty-key-on-ibm-j9%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53208183%2finvalidkeyexception-from-mac-init-when-used-with-empty-key-on-ibm-j9%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Landwehr

Reims

Javascript gets undefined on array