Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the key size for PBEWithMD5AndTripleDES?
    primarykey
    data
    text
    <p>I am trying to replace PBEWithMD5AndDES with PBEWithMD5AndTripleDES in existing code. So far, I am using the same passphrase that I was using before, and receiving this Exception:</p> <p>java.security.InvalidKeyException: Illegal key size</p> <p>I looked online and saw that DES uses a 64 bit key and TripleDES uses a 128 bit key. I am not clear on the details of how my passphrase is used to generate a key, and not sure where to look to understand this fully. My passphrase is 260 characters long. I tried doubling the length, but I get the same Exception.</p> <p>I am generating a PBEKeySpec from my passphrase, with an 8 byte salt and an iteration count of 12. I see that there's another constructor that takes a keyLength argument, but the documentation describes it as "to be derived," and I don't understand that. I have the idea that I need to modify the iteration count and/or supply a keyLength argument, but I don't want to just do this blindly without fully understanding what I am doing.</p> <p>Here is the basic outline of the code I'm currently using:</p> <pre><code>String passphrase = ... byte[] salt = ... int iterationCount = 12; String algorithm = "PBEWithMD5AndTripleDES"; KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), salt, iterationCount); SecretKey key = SecretKeyFactory.getInstance(algorithm).generateSecret(keySpec); Cipher cipher = Cipher.getInstance(key.getAlgorithm()); AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount); cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec); byte[] encoded = cipher.doFinal(data); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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