Java AES-128 ECB encryption
I have received a message from AT5 (Atrack) unite encoded with AES-128 ECB encryption and this is the key in hex (33333838000000000000000000000000)
the original key is in string "3388"
and this is the cipher that i received but i convert it to hex
Whenever I try to decrypt the message, I face this exception:
Error while decrypting: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Here is my code:
orginalString
?U??????}MgD?R???`????
#?j????g:N???@???$=???r?u?>~??Qh,?N?????3?8:?-E??;?b<J??I?v{?'o?m[?|?CY?n????K????>?ã??<?,???? ??f?'???}&?}?7r%??93??!u?0D?3Ig|??%'????*??`?Y^?M?4J?I?>?tIu???;?RR;2??{nrl??us
?R?F?oi????
String strToDecrypt = "E255898281B7C0B67D4D6744DB52FA1789F760B99B86A40A1F238B6ABCC690C1C9673A4E07EA03F79B40B2ACC8243DD098F4B10E72BA75CE3E7EE50F935168042CC74EA2F4BBE3D833F4383AE02D45C0119C3BC8623C4AD5189249FAB0BB767BA2276FB56D5BF27CE017435901DD8F6EC9DECD05B74BF51A99B1933E89C3A3AD06CA893CE72CDDEAE5F509E2D01B66A02717AADD0C917D26BA7DB1377225CCF23933E5F92175BD3044C63349677CEBC6251B27BE1FC9FD7FC32A0785F36019C2595E1EE783B64DB2344A14CE49C63EAB74174975FCE1C53BD95252113B0332CBD7A37B6E726CCFF675730DB052B14605E36F69AF11E8F3D2002D8BABEFFF508187E4C176329A3ABE08CF2B9A9F4812CF4084BACE87AD116F49C2ACD449767E758CE9184C60268AE3AAEADA052C91BF16241682E333671AC209D5BDC34CFD2B2D0C8D6D795D36A5FBD707FB56F71B3740BA86B1CEAC6E784E8E2B999CC6C9260A13F697A115C80F29C5AA38E95964731073CB051BB8A201EBAE6443A057AA69CFF41C9A593F88E2D6A712107EABCDE7042134F818268BF31896072C1B399B878BACCECC096F79A8D1835C2766EA639341E4AB22820D5AAD0F202BC896BD6C6F4D1FB1873C5BE06278D11E67F577D0120E054971088E7DB7E3A8139B20C6E22B86205BC0F4778A1DA0D6E50416FCE55DBC576A9F907FC706148204CA3C79993A4F37756427871C12EB379B4BFA0A518FFCA2BC698B1CA68AC9B3548B241C12669CEFAC9C8ECDB7B5A8149B";
secretKey = new SecretKeySpec("33333838000000000000000000000000".getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte cipherResult = cipher.doFinal(Base64.decodeBase64(strToDecrypt));
java encryption aes
add a comment |
I have received a message from AT5 (Atrack) unite encoded with AES-128 ECB encryption and this is the key in hex (33333838000000000000000000000000)
the original key is in string "3388"
and this is the cipher that i received but i convert it to hex
Whenever I try to decrypt the message, I face this exception:
Error while decrypting: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Here is my code:
orginalString
?U??????}MgD?R???`????
#?j????g:N???@???$=???r?u?>~??Qh,?N?????3?8:?-E??;?b<J??I?v{?'o?m[?|?CY?n????K????>?ã??<?,???? ??f?'???}&?}?7r%??93??!u?0D?3Ig|??%'????*??`?Y^?M?4J?I?>?tIu???;?RR;2??{nrl??us
?R?F?oi????
String strToDecrypt = "E255898281B7C0B67D4D6744DB52FA1789F760B99B86A40A1F238B6ABCC690C1C9673A4E07EA03F79B40B2ACC8243DD098F4B10E72BA75CE3E7EE50F935168042CC74EA2F4BBE3D833F4383AE02D45C0119C3BC8623C4AD5189249FAB0BB767BA2276FB56D5BF27CE017435901DD8F6EC9DECD05B74BF51A99B1933E89C3A3AD06CA893CE72CDDEAE5F509E2D01B66A02717AADD0C917D26BA7DB1377225CCF23933E5F92175BD3044C63349677CEBC6251B27BE1FC9FD7FC32A0785F36019C2595E1EE783B64DB2344A14CE49C63EAB74174975FCE1C53BD95252113B0332CBD7A37B6E726CCFF675730DB052B14605E36F69AF11E8F3D2002D8BABEFFF508187E4C176329A3ABE08CF2B9A9F4812CF4084BACE87AD116F49C2ACD449767E758CE9184C60268AE3AAEADA052C91BF16241682E333671AC209D5BDC34CFD2B2D0C8D6D795D36A5FBD707FB56F71B3740BA86B1CEAC6E784E8E2B999CC6C9260A13F697A115C80F29C5AA38E95964731073CB051BB8A201EBAE6443A057AA69CFF41C9A593F88E2D6A712107EABCDE7042134F818268BF31896072C1B399B878BACCECC096F79A8D1835C2766EA639341E4AB22820D5AAD0F202BC896BD6C6F4D1FB1873C5BE06278D11E67F577D0120E054971088E7DB7E3A8139B20C6E22B86205BC0F4778A1DA0D6E50416FCE55DBC576A9F907FC706148204CA3C79993A4F37756427871C12EB379B4BFA0A518FFCA2BC698B1CA68AC9B3548B241C12669CEFAC9C8ECDB7B5A8149B";
secretKey = new SecretKeySpec("33333838000000000000000000000000".getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte cipherResult = cipher.doFinal(Base64.decodeBase64(strToDecrypt));
java encryption aes
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24
add a comment |
I have received a message from AT5 (Atrack) unite encoded with AES-128 ECB encryption and this is the key in hex (33333838000000000000000000000000)
the original key is in string "3388"
and this is the cipher that i received but i convert it to hex
Whenever I try to decrypt the message, I face this exception:
Error while decrypting: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Here is my code:
orginalString
?U??????}MgD?R???`????
#?j????g:N???@???$=???r?u?>~??Qh,?N?????3?8:?-E??;?b<J??I?v{?'o?m[?|?CY?n????K????>?ã??<?,???? ??f?'???}&?}?7r%??93??!u?0D?3Ig|??%'????*??`?Y^?M?4J?I?>?tIu???;?RR;2??{nrl??us
?R?F?oi????
String strToDecrypt = "E255898281B7C0B67D4D6744DB52FA1789F760B99B86A40A1F238B6ABCC690C1C9673A4E07EA03F79B40B2ACC8243DD098F4B10E72BA75CE3E7EE50F935168042CC74EA2F4BBE3D833F4383AE02D45C0119C3BC8623C4AD5189249FAB0BB767BA2276FB56D5BF27CE017435901DD8F6EC9DECD05B74BF51A99B1933E89C3A3AD06CA893CE72CDDEAE5F509E2D01B66A02717AADD0C917D26BA7DB1377225CCF23933E5F92175BD3044C63349677CEBC6251B27BE1FC9FD7FC32A0785F36019C2595E1EE783B64DB2344A14CE49C63EAB74174975FCE1C53BD95252113B0332CBD7A37B6E726CCFF675730DB052B14605E36F69AF11E8F3D2002D8BABEFFF508187E4C176329A3ABE08CF2B9A9F4812CF4084BACE87AD116F49C2ACD449767E758CE9184C60268AE3AAEADA052C91BF16241682E333671AC209D5BDC34CFD2B2D0C8D6D795D36A5FBD707FB56F71B3740BA86B1CEAC6E784E8E2B999CC6C9260A13F697A115C80F29C5AA38E95964731073CB051BB8A201EBAE6443A057AA69CFF41C9A593F88E2D6A712107EABCDE7042134F818268BF31896072C1B399B878BACCECC096F79A8D1835C2766EA639341E4AB22820D5AAD0F202BC896BD6C6F4D1FB1873C5BE06278D11E67F577D0120E054971088E7DB7E3A8139B20C6E22B86205BC0F4778A1DA0D6E50416FCE55DBC576A9F907FC706148204CA3C79993A4F37756427871C12EB379B4BFA0A518FFCA2BC698B1CA68AC9B3548B241C12669CEFAC9C8ECDB7B5A8149B";
secretKey = new SecretKeySpec("33333838000000000000000000000000".getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte cipherResult = cipher.doFinal(Base64.decodeBase64(strToDecrypt));
java encryption aes
I have received a message from AT5 (Atrack) unite encoded with AES-128 ECB encryption and this is the key in hex (33333838000000000000000000000000)
the original key is in string "3388"
and this is the cipher that i received but i convert it to hex
Whenever I try to decrypt the message, I face this exception:
Error while decrypting: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 16 when decrypting with padded cipher
Here is my code:
orginalString
?U??????}MgD?R???`????
#?j????g:N???@???$=???r?u?>~??Qh,?N?????3?8:?-E??;?b<J??I?v{?'o?m[?|?CY?n????K????>?ã??<?,???? ??f?'???}&?}?7r%??93??!u?0D?3Ig|??%'????*??`?Y^?M?4J?I?>?tIu???;?RR;2??{nrl??us
?R?F?oi????
String strToDecrypt = "E255898281B7C0B67D4D6744DB52FA1789F760B99B86A40A1F238B6ABCC690C1C9673A4E07EA03F79B40B2ACC8243DD098F4B10E72BA75CE3E7EE50F935168042CC74EA2F4BBE3D833F4383AE02D45C0119C3BC8623C4AD5189249FAB0BB767BA2276FB56D5BF27CE017435901DD8F6EC9DECD05B74BF51A99B1933E89C3A3AD06CA893CE72CDDEAE5F509E2D01B66A02717AADD0C917D26BA7DB1377225CCF23933E5F92175BD3044C63349677CEBC6251B27BE1FC9FD7FC32A0785F36019C2595E1EE783B64DB2344A14CE49C63EAB74174975FCE1C53BD95252113B0332CBD7A37B6E726CCFF675730DB052B14605E36F69AF11E8F3D2002D8BABEFFF508187E4C176329A3ABE08CF2B9A9F4812CF4084BACE87AD116F49C2ACD449767E758CE9184C60268AE3AAEADA052C91BF16241682E333671AC209D5BDC34CFD2B2D0C8D6D795D36A5FBD707FB56F71B3740BA86B1CEAC6E784E8E2B999CC6C9260A13F697A115C80F29C5AA38E95964731073CB051BB8A201EBAE6443A057AA69CFF41C9A593F88E2D6A712107EABCDE7042134F818268BF31896072C1B399B878BACCECC096F79A8D1835C2766EA639341E4AB22820D5AAD0F202BC896BD6C6F4D1FB1873C5BE06278D11E67F577D0120E054971088E7DB7E3A8139B20C6E22B86205BC0F4778A1DA0D6E50416FCE55DBC576A9F907FC706148204CA3C79993A4F37756427871C12EB379B4BFA0A518FFCA2BC698B1CA68AC9B3548B241C12669CEFAC9C8ECDB7B5A8149B";
secretKey = new SecretKeySpec("33333838000000000000000000000000".getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(Cipher.DECRYPT_MODE, secretKey);
byte cipherResult = cipher.doFinal(Base64.decodeBase64(strToDecrypt));
java encryption aes
java encryption aes
edited Nov 16 '18 at 10:28
Mostafa Hafez
asked Nov 15 '18 at 15:34
Mostafa HafezMostafa Hafez
11
11
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24
add a comment |
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24
add a comment |
1 Answer
1
active
oldest
votes
Your strToDecrypt seems to be hex encoded, not base64 encoded .. so you need to hex decode it before decrypting, instead of base64 decoding. But actually you encrypted data if hex decoded, would also end up having an invalid size. Your hex string is 1200 hex chars = 600 bytes = 37.5 AES blocks of 16 bytes .. Something seems to be wrong with your data ..
Also, your key is also Hex encoded, so you need to hex decode it .. not just do a getBytes(..).
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
|
show 1 more comment
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f53322829%2fjava-aes-128-ecb-encryption%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your strToDecrypt seems to be hex encoded, not base64 encoded .. so you need to hex decode it before decrypting, instead of base64 decoding. But actually you encrypted data if hex decoded, would also end up having an invalid size. Your hex string is 1200 hex chars = 600 bytes = 37.5 AES blocks of 16 bytes .. Something seems to be wrong with your data ..
Also, your key is also Hex encoded, so you need to hex decode it .. not just do a getBytes(..).
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
|
show 1 more comment
Your strToDecrypt seems to be hex encoded, not base64 encoded .. so you need to hex decode it before decrypting, instead of base64 decoding. But actually you encrypted data if hex decoded, would also end up having an invalid size. Your hex string is 1200 hex chars = 600 bytes = 37.5 AES blocks of 16 bytes .. Something seems to be wrong with your data ..
Also, your key is also Hex encoded, so you need to hex decode it .. not just do a getBytes(..).
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
|
show 1 more comment
Your strToDecrypt seems to be hex encoded, not base64 encoded .. so you need to hex decode it before decrypting, instead of base64 decoding. But actually you encrypted data if hex decoded, would also end up having an invalid size. Your hex string is 1200 hex chars = 600 bytes = 37.5 AES blocks of 16 bytes .. Something seems to be wrong with your data ..
Also, your key is also Hex encoded, so you need to hex decode it .. not just do a getBytes(..).
Your strToDecrypt seems to be hex encoded, not base64 encoded .. so you need to hex decode it before decrypting, instead of base64 decoding. But actually you encrypted data if hex decoded, would also end up having an invalid size. Your hex string is 1200 hex chars = 600 bytes = 37.5 AES blocks of 16 bytes .. Something seems to be wrong with your data ..
Also, your key is also Hex encoded, so you need to hex decode it .. not just do a getBytes(..).
edited Nov 15 '18 at 16:00
answered Nov 15 '18 at 15:46
Ebbe M. PedersenEbbe M. Pedersen
5,57031938
5,57031938
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
|
show 1 more comment
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
just because a string contains characters allowed in base 16(hexadecimal) does not mean it has to be hex decoded(you proved it yourself that it doesn't make any sense if it was supposed to either) also having a key length of 32 bytes has nothing wrong with it(neither has containing hex characters within key bytes) so we can just call getbytes.
– kamyar haqqani
Nov 15 '18 at 19:28
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani: 1) Since it is supposedly cipher and hundred of bytes long, yeah, it basically does prove its hex-encoded; 2) Since he says he's using AES128, then, yeah, the key is hex-encoded also, but 3) much of the hex-encoded cipher is too non-random to be cipher anyways.
– James K Polk
Nov 15 '18 at 20:34
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
@kamyarhaqqani I wrote that it SEEMS to be hex ..I chose that wording on purpose to counter this kind of pedantic discussions. As for the key, OP explicit claims in the question that it's in hex, and the length of this hex key matches exactly the 128 bit key length needed for the AES-128 - also stated in the question.
– Ebbe M. Pedersen
Nov 15 '18 at 22:42
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
you are right about the key and this discussion being pedantic. by saying "you need to hex decode it before decryption" you are actually concluding that any string which contains base 16 allowed chars(and 'seems' to be hex) is always a hex encoded string, it is not!
– kamyar haqqani
Nov 16 '18 at 0:30
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
for the key they use string "3388" and i convert it to hex to get its 16 bytes
– Mostafa Hafez
Nov 16 '18 at 10:12
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f53322829%2fjava-aes-128-ecb-encryption%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
share the code of how strToDecrypt is generated. Base64.decodeBase64(strToDecrypt) would result in a byte array of size 900. 900 has 4 remaining when divided by 16.
– kamyar haqqani
Nov 15 '18 at 19:11
it's being generated from hardware device we only control the key which is "3388"
– Mostafa Hafez
Nov 16 '18 at 10:24