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
hmac j9
add a comment |
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
hmac j9
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
add a comment |
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
hmac j9
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
hmac j9
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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