// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/EncryptionConstants.java
// public class EncryptionConstants {
//     public static final String AES_CIPHER = "AES";
//     public static final String BLOCK_MODE_CBC = "CBC";
//     public static final String ENCRYPTION_PADDING_PKCS5 = "PKCS5Padding";
//     public static final String ENCRYPTION_PADDING_PKCS7 = "PKCS7Padding";
// 
//     /**
//       * While this specifies PKCS5Padding and a 256 bit key, a historical artifact in the Sun encryption
//       * implementation interprets PKCS5 to be PKCS7 for block sizes over 8 bytes. In Android M this
//       * appears to have been corrected so that PKCS7Padding will work when instantiating a Cipher object.
//       */
//     public static final String AES_CBC_PADDED_TRANSFORM = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS5;
//     public static final String AES_CBC_PADDED_TRANSFORM_ANDROID_M = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS7;
//     public static final int AES_256_KEY_LENGTH_BITS = 256;
// 
//     public static final String DIGEST_SHA256 = "SHA256";
// 
//     public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
// }


import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.util.Log;
import com.bottlerocketstudios.vault.EncryptionConstants;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

                keyGenerator.init(new KeyGenParameterSpec.Builder(mKeyAlias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                        .setBlockModes(mBlockMode)
                        .setUserAuthenticationRequired(true)
                        .setUserAuthenticationValidityDurationSeconds(mAuthDurationSeconds)
                        .setEncryptionPaddings(mPadding)
                        .build());

                return keyGenerator.generateKey() != null;
            } catch (KeyStoreException e) {
                Log.e(TAG, "Caught java.security.KeyStoreException", e);
            } catch (CertificateException e) {
                Log.e(TAG, "Caught java.security.cert.CertificateException", e);
            } catch (NoSuchAlgorithmException e) {
                Log.e(TAG, "Caught java.security.NoSuchAlgorithmException", e);
            } catch (InvalidAlgorithmParameterException e) {
                Log.e(TAG, "Caught java.security.InvalidAlgorithmParameterException", e);
            } catch (NoSuchProviderException e) {
                Log.e(TAG, "Caught java.security.NoSuchProviderException", e);
            } catch (IOException e) {
                Log.e(TAG, "Caught java.io.IOException", e);
            }
        }
        return false;
    }

    @Override
    public void clearKey(Context context) {
        synchronized (mKeyLock) {
            try {
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/EncryptionConstants.java
// public class EncryptionConstants {
//     public static final String AES_CIPHER = "AES";
//     public static final String BLOCK_MODE_CBC = "CBC";
//     public static final String ENCRYPTION_PADDING_PKCS5 = "PKCS5Padding";
//     public static final String ENCRYPTION_PADDING_PKCS7 = "PKCS7Padding";
// 
//     /**
//       * While this specifies PKCS5Padding and a 256 bit key, a historical artifact in the Sun encryption
//       * implementation interprets PKCS5 to be PKCS7 for block sizes over 8 bytes. In Android M this
//       * appears to have been corrected so that PKCS7Padding will work when instantiating a Cipher object.
//       */
//     public static final String AES_CBC_PADDED_TRANSFORM = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS5;
//     public static final String AES_CBC_PADDED_TRANSFORM_ANDROID_M = AES_CIPHER + "/" + BLOCK_MODE_CBC + "/" + ENCRYPTION_PADDING_PKCS7;
//     public static final int AES_256_KEY_LENGTH_BITS = 256;
// 
//     public static final String DIGEST_SHA256 = "SHA256";
// 
//     public static final String ANDROID_KEY_STORE = "AndroidKeyStore";
// }


// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/KeychainAuthenticatedKeyStorage.java
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.security.keystore.KeyGenParameterSpec;
import android.security.keystore.KeyProperties;
import android.util.Log;
import com.bottlerocketstudios.vault.EncryptionConstants;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;


                keyGenerator.init(new KeyGenParameterSpec.Builder(mKeyAlias, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                        .setBlockModes(mBlockMode)
                        .setUserAuthenticationRequired(true)
                        .setUserAuthenticationValidityDurationSeconds(mAuthDurationSeconds)
                        .setEncryptionPaddings(mPadding)
                        .build());

                return keyGenerator.generateKey() != null;
            } catch (KeyStoreException e) {
                Log.e(TAG, "Caught java.security.KeyStoreException", e);
            } catch (CertificateException e) {
                Log.e(TAG, "Caught java.security.cert.CertificateException", e);
            } catch (NoSuchAlgorithmException e) {
                Log.e(TAG, "Caught java.security.NoSuchAlgorithmException", e);
            } catch (InvalidAlgorithmParameterException e) {
                Log.e(TAG, "Caught java.security.InvalidAlgorithmParameterException", e);
            } catch (NoSuchProviderException e) {
                Log.e(TAG, "Caught java.security.NoSuchProviderException", e);
            } catch (IOException e) {
                Log.e(TAG, "Caught java.io.IOException", e);
            }
        }
        return false;
    }

    @Override
    public void clearKey(Context context) {
        synchronized (mKeyLock) {
            try {
                KeyStore keyStore = KeyStore.getInstance(EncryptionConstants.ANDROID_KEY_STORE);