Code example for PBEKeySpec

        final int iterations = 1000;
        // Generate a 256-bit key 
        final int keyLength = 256;
        final KeySpec spec = new PBEKeySpec(password, salt, iterations, keyLength);
        return SecurePreferences.encode(SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1")
    private static String generateAesKeyValue() throws NoSuchAlgorithmException {
        // Do *not* seed secureRandom! Automatically seeded from system entropy 
        final SecureRandom random = new SecureRandom();
        // Use the largest AES key length which is supported by the OS 
        final KeyGenerator generator = KeyGenerator.getInstance("AES");
        try { 
            generator.init(256, random);
        } catch (Exception e) {
            try { 
                generator.init(192, random);