0
votes

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?

1
Which line gives you a BadPaddingException?Sam Estep
decryptedData = cipher.doFinal(dataBytes);Nikita G.
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)?Artjom B.
All I know that is binary data from GPS tracker, encryption key and algorythm.Nikita G.

1 Answers

2
votes

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.