Hi,
I'm attempting to generate a new cipher key using a string that was negotiated earlier on. On running the code I get the error:
Exception in thread "main" java.lang.IllegalArgumentException: Missing argument
at javax.crypto.spec.SecretKeySpec.<init>(DashoA13*..)
at shared.Cryptographer.makeCipher(Cryptographer.java:254)
at client.Main.main(Main.java:60)
Java Result: 1
the code is as follow:
public void makeCipher(String key, int Skeytype){
try {
byte[] salt = new byte[16];
for (int i = 0; i < 16; i++)
salt[i] = (byte) 0;
PBEKeySpec password = new PBEKeySpec(key.toCharArray(), salt, 1000, 128);
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
PBEKey pbekey = (PBEKey) factory.generateSecret(password);
SecretKey encKey = new SecretKeySpec(pbekey.getEncoded(), ciphtype);
if(Skeytype == 0 || Skeytype == 1)
cipherkeys[Skeytype] = encKey;
else
System.out.println("Invalid Skeytype");
cipher = Cipher.getInstance(ciphtype+"/ECB/PKCS5Padding");
} catch (NoSuchPaddingException ex) {
System.out.println("NoSuchPaddingException: "+ex.toString());
} catch (InvalidKeySpecException ex) {
System.out.println("InvalidKeySpecException: "+ex.toString());
} catch (NoSuchAlgorithmException ex) {
System.out.println("NoSuchAlgorithmException: "+ex.toString());
}
}
The error comes from this line:
SecretKey encKey = new SecretKeySpec(pbekey.getEncoded(), ciphtype);
According to the API for SecretKeySpec I'm using the constructor properly and to the best of my knowledge and understanding of the installation instructions, the unlimited security .jars are installed on my system properly unless netbeans needs me to put them somewhere special.
Thanks for the help,
~Jordan