Code example for PBEKeySpec

0
     * rejected. 
     */ 
    public SecretKey genKeyPwkdf2(String password, byte[] salt, int iterations)
            throws NoSuchAlgorithmException, InvalidKeySpecException { 
        SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
        PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, iterations, KEY_BITS);
        SecretKey generatedKey = f.generateSecret(keySpec);
        return generatedKey;
    } 
 
    /** 
     * Generates a random initialisation vector. 
     * @return A random initialisation vector. 
     */ 
    public byte[] getIv() { 
        SecureRandom sr = new SecureRandom();
        byte[] iv = new byte[IV_BYTES];
        sr.nextBytes(iv);
        return iv;
    }