I am unfortunately not so familiar with cryptography, but I need to implement this algorithm in java8. That means, I already have some data encrypted with this approach written in C, and the key, which is 256bit, and I need to decrypt this data using some java code. Note that all that we have in Erdelsky's approach is a key, there's no 'salt' and no 'initializing vector' (at least explicit, but I may mistake).
What have I tried? Well, a bit:
- I tried BouncyCastle, but it fails to decrypt my data (it uses 'iv', I set it all zero, so it might be a problem)
I am using java 1.8.112 I got an 'Illegal key size or default parameters' exception and I tried to Hack my JDK to let it work with 256bit keys, (it uses 'iv' as well) but it fails to decrypt my data as well. The code is the following:
public static void DecryptData(byte[] Contents, int NumBytes, byte[] KeyBytes, int KeyOffset, int NumKeyBytes) { final int AESBlockSize = 16; final byte[] EncryptionDecryptionBuffer = new byte[AESBlockSize]; final byte[] InitializingVector = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; try { final Cipher AES256Cipher = Cipher.getInstance("AES/CBC/NoPadding"); final SecretKeySpec secretKeySpec = new SecretKeySpec(KeyBytes, KeyOffset, NumKeyBytes, "AES"); AES256Cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, new IvParameterSpec(InitializingVector)); // Decrypt the data a block at a time for (int Offset = 0; Offset < NumBytes; Offset += AESBlockSize) { // Update and copy to the EncryptionDecryptionBuffer AES256Cipher.update(Contents, Offset, AESBlockSize, EncryptionDecryptionBuffer); // Copy to the initial array System.arraycopy(EncryptionDecryptionBuffer, 0, Contents, Offset, AESBlockSize); } } catch (GeneralSecurityException e) { throw new RuntimeException(e); } }
I am still looking for the solution, please help. Thanks.