Code example for PBEKeySpec

0
     * @return 
     * @throws SecurityFeaturesException 
     */ 
    public static SecretKey keyFromPassword(Context ctx, String password, byte[] salt) throws SecurityFeaturesException 
    { 
        PBEKeySpec spec = new PBEKeySpec(password.toCharArray(), salt, CIPHER_KEY_ITERATIONS, CIPHER_KEY_SIZE);
                
        SecretKeyFactory f;
        try { 
            // First convert Key to something more secure using the pbekeyspec 
            f = SecretKeyFactory.getInstance(PASSWORD_KEY_ALGORITHM);
            SecretKey x = f.generateSecret(spec);
            return x;   
        
             
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();           
        } catch (InvalidKeySpecException e) {
            e.printStackTrace();
        } 
        throw new SecurityFeaturesException();