title: DESedeKeySpec Wrong key size
body: <p>I need to use double length 3DES key to encrypt random 8 bytes and then use the encrypted value to derive a new 3DES key. </p>
  
  <p>When I attempt to instantiate the DESedeKeySpec with the encryptedRandomValue, I get an error message "Wrong key size". Can you advise me how to fix this issue? </p>
  
  <p>DESedeKeySpec myKeySpec = new DESedeKeySpec(encryptedRandomValue);       </p>
  
  <p>I can avoid getting this error if all my SecretKeys are single DES key. But I need to use double length 3DES key and ECB mode.</p>
  
  <p>Here is my code; </p>
  
  <pre><code>    // Generate double length 3DES Master Key
      KeyGenerator masterEncKeyGenerator = KeyGenerator.getInstance("DESede");
      masterEncKeyGenerator.init(112);
      SecretKey masterKey = masterEncKeyGenerator.generateKey();
  
      //Prepare random bytes
      byte[] randomKeyValue = "rn4yrbdy".getBytes();
  
      // Encrypt random bytes with the 3DES Master key
      final Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
      cipher.init(Cipher.ENCRYPT_MODE, masterKey);
      byte[] encryptedRandomValue = cipher.doFinal(randomKeyValue);
  
      // Derive new key 3DES Key
      SecretKeyFactory mySecretKeyFactory = SecretKeyFactory.getInstance("DESede");
      DESedeKeySpec myKeySpec = new DESedeKeySpec(encryptedRandomValue);
      SecretKey derivedKey = mySecretKeyFactory.generateSecret(myKeySpec);
  </code></pre>
  
  <p>I realize why I am getting this error. It is because the DESedeKeySpec needs to take in 24 bytes as key material but I am giving it only 8. But that's the requirement I have: to produce a 3DES key out of encrypted, with master 3DES key, random 8 bytes data...</p>