Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void generarClave() {
- try {
- keyStore = KeyStore.getInstance("AndroidKeyStore");
- } catch (Exception e) {
- e.printStackTrace();
- }
- //Se instancia KeyGenerator con los diferentes parámetros de seguridad.
- try {
- keyGenerator=KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
- }catch (NoSuchAlgorithmException | NoSuchProviderException e){
- throw new RuntimeException("Fallo en obtener instancia de KeyGenerator",e);
- }
- //Generar la clave que va a ser usado por el cifrador en el proceso de encripción.
- try{
- keyStore.load(null);
- keyGenerator.init(new KeyGenParameterSpec.Builder(KEY_NAME, KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
- .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
- .setUserAuthenticationRequired(true)
- .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7).build());
- }catch (NoSuchAlgorithmException| InvalidAlgorithmParameterException|CertificateException| IOException e){
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement