0

Trying to decrypt data as byte array encrypted with AES-128 with String key "keykeykeykeykey1"

code:

byte[] dataBytes = new byte []{(byte)0xf3,(byte)0x8b,(byte)0x0c,(byte)0xb3,(byte)0xa3,(byte)0x26,(byte)0x12,(byte)0x23,(byte)0xe0,(byte)0xe0,(byte)0x9f,(byte)0x1f,(byte)0x28,(byte)0x01,(byte)0x28,(byte)0x35};
SecretKeySpec secretKeySpec = new SecretKeySpec("keykeykeykeykey1".getBytes("UTF-8"), "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
byte[] decryptedData = cipher.doFinal(dataBytes); //this line throws exception

gives me BadPaddingException. What I missed?

4
  • Which line gives you a BadPaddingException? Commented Jul 1, 2015 at 11:15
  • decryptedData = cipher.doFinal(dataBytes); Commented Jul 1, 2015 at 11:17
  • You have to know how it is encrypted, before trying to decrypt it. What's the mode of operation (ECB, CBC, ...)? What's the padding (None, Zero, PKCS#7, ...)? How is the actual key derived from key (simple decoding, MD5, SHA256, PBKDF2, ...)? What are key size and block size? How is the ciphertext laid out (IV included in front or back, auth tag included f or b)? Commented Jul 1, 2015 at 11:33
  • All I know that is binary data from GPS tracker, encryption key and algorythm. Commented Jul 1, 2015 at 11:35

1 Answer 1

2

You don't specify the mode or padding in your Cipher algorithm. You need to establish what values were used when the data was enciphered.

When you change the algo to "AES/ECB/NOPADDING" there is no error, but this might not necessarily be the right mode or padding.

Sign up to request clarification or add additional context in comments.

1 Comment

Online tools like this gives me right decryption and You're right. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.