Forum Discussion
Encrypt with AES::encrypt but, how to decrypt with Java?
With Java, you must get a Cypher:
Cipher decryptCipher = Cipher.getInstance("AES");
decryptCipher.init(Cipher.DECRYPT_MODE, getSecretKey());
byte[] deciphertext = decryptCipher.doFinal(encripted);
String decryptedString = new String(deciphertext);
But this code causes this error:
javax.crypto.IllegalBlockSizeException: 9 trailing bytes
at gnu.javax.crypto.jce.cipher.CipherAdapter.engineDoFinal(libgcj.so.90)
at javax.crypto.Cipher.doFinal(libgcj.so.90)
at javax.crypto.Cipher.doFinal(libgcj.so.90)
The problem is with PADDING, but I don't know exactly where does the problem is.
When I get the Cipher, I can choose with diferent options:
Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
Cipher decryptCipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
Cipher decryptCipher = Cipher.getInstance("AES/CFB8/NoPadding");
...
Maybe the problem is I don't get the good Cipher.
Can anybody help me?
Thanks.
- spark_86682Historic F5 AccountAES::encrypt uses CWC mode encryption. I don't know Java, but from some brief searches it doesn't appear to support that encryption mode.
- IheartF5_45022NacreousHi, I think this has been solved now with the new CRYPTO:: commands in v11. It can now use a encryption mode which is also implemented in Java. The CRYPTO:: doco is here (http://devcentral.f5.com/wiki/iRules.CRYPTO.ashx), but so far is a bit light on detail.
- Colin_Walker_12Historic F5 AccountJoanna,
- yoggitNimbostratusIs there a way to specify padding or not in the CRYPTO::encrypt and CRYPTO::encrypt commands?
- spark_86682Historic F5 AccountThere is no way to control the padding, no. PKCS padding is always used. I would recommend filing an RFE for this. Sorry that this probably isn't what you wanted to hear.
- Wolf46_144992Nimbostratus
Hi Spark,
We are having a similar issue between F5 and our Java application. Do you know if there is a way to make encryption and decryption work between systems?
Our developers are using AES-128-CBC with PKCS5 padding. However when decrypting the data with an iRule on F5 we are not capable of decrypting the data correctly.
Is there a way to know which type of PKCS, F5 is using please?
Can someone explain me the difference between AES::encrypt and CRYPTO::encrypt ?
Thanks and Cheers, Bob
Please Help its urgent!!!
Cheers, Bob
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com