Note that there are some explanatory texts on larger screens.

plurals
  1. POInvalidKeyException Illegal key size
    text
    copied!<p>I have a test which runs great on my development MacBook Pro, but fails to run in continuous integration TeamCity server.</p> <p>The error is following:</p> <pre><code>java.security.InvalidKeyException: Illegal key size at javax.crypto.Cipher.a(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) at javax.crypto.Cipher.init(DashoA13*..) </code></pre> <p>Both development box and TeamCity uses Java 1.6 and I use BouncyCastle library for the need of special AES encryption.</p> <p>The code is following:</p> <pre><code>private byte[] aesEncryptedInfo(String info) throws UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidParameterSpecException, InvalidAlgorithmParameterException, NoSuchProviderException { Security.addProvider(new BouncyCastleProvider()); SecretKey secret = new SecretKeySpec(CUSTOMLONGSECRETKEY.substring(0, 32).getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, secret, new IvParameterSpec(VECTOR_SECRET_KEY.getBytes())); return cipher.doFinal(info.getBytes("UTF-8")); } </code></pre> <p><strong>UPDATE</strong></p> <p>Looks like according to the selected answer I have to modify something on my TeamCity installation and it will possibly affect some user installations - so its not a good choice I have to switch to another crypto library to do that without limitations. So probably bouncy castle will help.</p> <p><strong>UPDATE 2</strong></p> <p>I actually switched to use BouncyCastle to avoid this limitation. Note this only works if you use own BC classes directly, not the BC provider.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload