I am using Java AES encryption to encrypt data which will be sent to a recipient. Each recipient will have their own key, which both they and I know.
The idea is that they can decrypt the data using freely available AES decryption tools.
Here is the my code:
public class AESencrypt {
private static final String ALGO = "AES/CBC/PKCS5Padding";
private static final byte[] keyValue = new byte[]{'T', 'h', 'e', 'B', 'e', 's', 't', 'S', 'e', 'c', 'r', 'e', 't', 'K', 'e', 'y'};
private static byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
public void String encryptToFile(String filename, String data) throws Exception {
Key key = new SecretKeySpec(keyValue, "AES");
Cipher c = Cipher.getInstance(ALGO);
IvParameterSpec ivspec = new IvParameterSpec(iv);
c.init(Cipher.ENCRYPT_MODE, key, ivspec);
byte[] encVal = c.doFinal(data.getBytes());
FileOutputStream fileOutputStream = new FileOutputStream(filename);
fileOutputStream.write(encVal);
fileOutputStream.close();
}
public static void main(String[] args) throws Exception {
encryptToFile("foo.aes", "hellothere");
}
}
}
To verify this, I used an Online AES Encryption / Decryption Tool to decrypt some sample data (which worked fine!).
Now, I would like to use a free AES decryption tool so that the recipients can decrypt the data on their PC without using an online tool - and here is where the frustration starts.
I started installing and testing out various different AES decryptor tools: I carefully enter the key, choose the CBC algorithm, select my file and hit "decrypt", and yet none of the tools can decode my sample file foo.aes - they all fail with errors and in one case gave an empty file of zero bytes.
I tried this with at least 4 different AES encryptor/decryptor tools, and none of them worked to decrypt my file, which leads me to believe there might be a problem with my code.
- CriptAES
- AES Crypt
- Advanced AES Encryptor
- Cr!ptAES
If anyone can look over my code that would be greatly appreciated.
Alternatively there may be an AES decryptor tool that will work with the code above.