I have an issue with my java code. I\'m trying to encrypt a file. However, when I run my java code I get \"java.security.InvalidKeyException: Invalid AES key length: 162 byt
AES is a symmetric algorithm, hence they use of KeyPairGenerator
is not supported. To generate a key with AES you call KeyGenerator
KeyGenerator kgen = KeyGenerator.getInstance("AES");
kgen.init(128); //set keysize, can be 128, 192, and 256
By looking at the rest of your code, it looks like you are trying to achive asymmetric encryption (since you call getPublic() and getPrivate()
etc), so I advice you to switch to using RSA or any other asymmetric algorithm that java supports. You will most likley only need to replace AES
with RSA
in your getInstance();
calls, and pherhaps some fine-tuning. Good luck