public static String generate128BitKey ( String password , String salt ) throws NoSuchAlgorithmException , UnsupportedEncodingException , InvalidKeySpecException { SecretKeyFactory factory = SecretKeyFactory . getInstance ( "PBKDF2WithHmacSHA256" ) ; KeySpec spec = new PBEKeySpec ( password . toCharArray ( ) , salt . getBytes ( ) , 65536 , 128 ) ; SecretKey key = factory . generateSecret ( spec ) ; byte [ ] keybyte = key . getEncoded ( ) ; return Base64 . getEncoder ( ) . encodeToString ( keybyte ) ; }
Utility method to help generate a strong 128 bit Key to be used for the DefaultAESCBCCipher .