//Return false if cipher initialization failed//
private boolean initCipher() {
        try {
            //Obtain a cipher instance and configure it with the properties required for fingerprint authentication//
            if(this.cipher == null) {
                this.cipher = Cipher.getInstance(
                        KeyProperties.KEY_ALGORITHM_AES + "/"
                                + KeyProperties.BLOCK_MODE_CBC + "/"
                                + KeyProperties.ENCRYPTION_PADDING_PKCS7);
            }
        } catch (NoSuchAlgorithmException |
                NoSuchPaddingException e) {
            e.printStackTrace();
            return false;
        }
        try {
            if(this.secretKey == null) {
                this.secretKey = generateKey();
            }
            if(this.keyStore != null) {
                if(!this.keystoreInitialized) {
                    this.keyStore.load(null);
                    this.keystoreInitialized = true;
                }
            }
//            key = (SecretKey) this.keyStore.getKey(keyName, null); todo needed?
            if(this.cipher != null) {
                if (!this.cipherInitialized) {
                    this.cipher.init(Cipher.ENCRYPT_MODE, this.secretKey);
                    this.cipherInitialized = true;
                }
            }
            //Return true if the cipher has been initialized successfully//
            return true;
        } catch (KeyPermanentlyInvalidatedException e) {
            //Return false if cipher initialization failed//
            return false;
        } catch (CertificateException //KeyStoreException
                | IOException //UnrecoverableKeyException
                | NullPointerException
                | NoSuchAlgorithmException | InvalidKeyException e) {
            e.printStackTrace();
            return false;
        }
    }
return true;
} catch (KeyPermanentlyInvalidatedException e) {
//Return false if cipher initialization failed//
return false;
} catch (CertificateException //KeyStoreException
// key = (SecretKey) this.keyStore.getKey(keyName, null); todo needed?
if(this.cipher != null) {
if (!this.cipherInitialized) {
this.cipher.init(Cipher.ENCRYPT_MODE, this.secretKey);
this.cipherInitialized = true;
}
}
//Return true if the cipher has been initialized successfully//
return true;
} catch (KeyPermanentlyInvalidatedException e) {
//Return false if cipher initialization failed//
return false;
} catch (CertificateException //KeyStoreException
| IOException //UnrecoverableKeyException
| NullPointerException
| NoSuchAlgorithmException | InvalidKeyException e) {
e.printStackTrace();
return false;
}
}
try {
if(this.secretKey == null) {
this.secretKey = generateKey();
}
if(this.keyStore != null) {
if(!this.keystoreInitialized) {
this.keyStore.load(null);
this.keystoreInitialized = true;
}
}
// key = (SecretKey) this.keyStore.getKey(keyName, null); todo needed?
if(this.cipher != null) {
if (!this.cipherInitialized) {
this.cipher.init(Cipher.ENCRYPT_MODE, this.secretKey);
this.cipherInitialized = true;
}
}
//Return true if the cipher has been initialized successfully//
return true;
} catch (KeyPermanentlyInvalidatedException e) {
//Return false if cipher initialization failed//
return false;
} catch (CertificateException //KeyStoreException
| IOException //UnrecoverableKeyException
| NullPointerException
| NoSuchAlgorithmException | InvalidKeyException e) {
e.printStackTrace();
return false;
}
}