Basically, I'm trying to hash a user specified string into a 256 bit byte array to be used as a key when encrypting data using Java's implementation of AES256. I keep getting this runtime exception:
java.security.InvalidKeyException: Illegal key size or default parameters
I suspect it's because some of the bytes aren't 8 bits long, so the overall key size isn't 256 bits. I was wondering how to pad them out with 0's on the left, so ensure the length of the key?
EDIT:
This is the conversion from a value to a message digest:
MessageDigest hasher = MessageDigest.getInstance("SHA-256");
// Use the factory method to get the SHA-256 instance of a MessageDigest object.
hasher.update(input.getBytes());
// Update the message digest object with the bytes of the value to hash.
return hasher.digest();
// Hash the value and return the string representation.
This is the encryption, using the output from "hasher".
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
cryptoTool.init(Cipher.ENCRYPT_MODE, key); // This is where the error fires.
return String.valueOf(cryptoTool.doFinal(plaintext.getBytes()));