However you want to do it, generate an array of bytes at least as long as your intended cipher requires. Most ciphers now require 16, 24, or 64 byte blocks as keys.
SecretKeySpec has two constructors which give you a choice of exactly the right sized array of bytes or some block of bytes selected from a larger byte array.
byte[] keyArray1 = new byte[16];Here are the two SecretKeySpec constructors :
byte[] keyArray2 = new byte[24];
byte[] keyArray3 = new byte[64];
SecretKeySpec(byte[] key, String algorithm)
SecretKeySpec key1 = new SecretKeySpec(keyArray1,"AES");
SecretKeySpec(byte[] key, int offset, int len, String algorithm)
SecretKeySpec key2 = new SecretKeySpec(keyArray3,13,16,"Serpent");
Here is the link to the official Oracle Documentation
No comments:
Post a Comment