· 7 years ago · Jul 23, 2018, 05:04 PM
1 public boolean cipherInit(){
2 try {
3 cipher= Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES+"/"+KeyProperties.BLOCK_MODE_CBC+"/"+KeyProperties.ENCRYPTION_PADDING_PKCS7);
4 }catch (NoSuchAlgorithmException|NoSuchPaddingException e){
5 throw new RuntimeException("Fallo en obtener el Cifrador",e);
6 }
7 try{
8 keyStore.load(null);//Se carga el keystore container
9 //Se genera una clave secreta
10 SecretKey key= (SecretKey)keyStore.getKey(KEY_NAME,null);
11 //Se inicia el cifrador
12 cipher.init(Cipher.ENCRYPT_MODE, key);
13 //Si esque el cifrador inicia correctamente, retorna true.
14 return true;
15 }catch (KeyPermanentlyInvalidatedException e){
16 return false;
17 }catch (KeyStoreException|CertificateException|UnrecoverableKeyException|IOException|NoSuchAlgorithmException|InvalidKeyException e){
18 throw new RuntimeException("Fallo en iniciar el Cifrador",e);
19 }
20 }