Advertisement
taisonik

Untitled

Jul 23rd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1.     protected void generarClave() {
  2.         try {
  3.             keyStore = KeyStore.getInstance("AndroidKeyStore");          
  4.         } catch (Exception e) {
  5.             e.printStackTrace();
  6.         }
  7.  
  8.         //Se instancia KeyGenerator con los diferentes parámetros de seguridad.
  9.         try {
  10.             keyGenerator=KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
  11.         }catch (NoSuchAlgorithmException | NoSuchProviderException e){
  12.             throw new RuntimeException("Fallo en obtener instancia de KeyGenerator",e);
  13.         }
  14.         //Generar la clave que va a ser usado por el cifrador en el proceso de encripción.
  15.         try{
  16.             keyStore.load(null);
  17.             keyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
  18.             .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
  19.             .setUserAuthenticationRequired(true)
  20.             .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7).build());
  21.         }catch (NoSuchAlgorithmException| InvalidAlgorithmParameterException|CertificateException| IOException e){
  22.             throw new RuntimeException(e);
  23.         }
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement