0

The code below works, but it works only at 128 bits. I'm not failing because of the JCE's lack of support for high-rate encryption (I've taken care of this), but I'm looking for a way to support a non-default key rate.

def encrypt(iv4bytes: Array[Byte], pass: String, indata: Array[Byte]): Array[Byte] = {
    val cipher = Cipher.getInstance("AES/CBC/NoPadding", "SunJCE") // Get a cipher object
    val key = new SecretKeySpec(pass.getBytes("UTF-8"), "AES") // Get our key object
    cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv4bytes)) // Initialize crypto
    return cipher.doFinal(indata) // And do the encryption
  }
user500123
  • 617
  • 6
  • 14
  • try [upgrading your JCE policies](http://stackoverflow.com/questions/19856324/exception-in-thread-main-java-security-invalidkeyexception-illegal-key-size-o) – jmj May 19 '15 at 00:37
  • I've already done this as noted, but every time I try anything but 128 bits, I still get invalid key exceptions of one form or another. From what I can tell, it relates to how I generate the SecretKey object. The above code is the "short form", but I've not found the "long way" – user500123 May 20 '15 at 02:28

0 Answers0