When you are using Oracle default JCE provider or BouncyCastle provider, if you only use key size 64 or 128 bits, for BouncyCastle, you need to call:
Security.addProvider( new BouncyCastleProvider() );
for Oracle JCE provider, you don't need to add anything specifically.
Then you may call for example:
// This use the default ECB mode, and PKCS7Padding
Cipher cipher = Cipher.getInstance("AES", "BC");
So, it will the same as
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC" );
**** Note:
ECB has a problem to encrypt data, the cipher text shows the same pattern as the plain text, For example:
545454541234567854545454123443215454545412345678 2A8733982F64E6B35873778337192DA3931AE70A734C58761BC2A82498A133CC2A8733982F64E6B35873778337192DA33FE7286ABDE5F03943D5777020259626
More Details are here
The normal JDK download ships with a set of policy files that places certain restrictions on the key sizes that can be used. Key sizes are limited in general to 128 bits (except for the symmetric cipher Triple-DES) and RSA key generation is limited to 2,048 bits.
But if you want to use the key size greater than 128 bits, you have to download the unrestricted policy files, for Java 6, they are here:
After you unzip them you will get two JAR files:
Backup your existing files under the following location: $JAVA_HOME/lib/security
and then put the unzipped two files in this directory, now you could use the keys with size greater than 128.
If you don't do this, you will get the following exception:
Posted via email from Progress
No comments:
Post a Comment