How can I encrypt my password - Android Studio

Does anyone know how to encrypt the password that the user adds to the password field?

I tried this tutorial but I didn’t get his job.

https://gist.github.com/aogilvie/6267013#file-string_encrypt_decrypt-md

I hope someone can help me :(

+5
source share
2 answers
public class AESCrypt { private static final String ALGORITHM = "AES"; private static final String KEY = "1Hbfh667adfDEJ78"; public static String encrypt(String value) throws Exception { Key key = generateKey(); Cipher cipher = Cipher.getInstance(AESCrypt.ALGORITHM); cipher.init(Cipher.ENCRYPT_MODE, key); byte [] encryptedByteValue = cipher.doFinal(value.getBytes("utf-8")); String encryptedValue64 = Base64.encodeToString(encryptedByteValue, Base64.DEFAULT); return encryptedValue64; } public static String decrypt(String value) throws Exception { Key key = generateKey(); Cipher cipher = Cipher.getInstance(AESCrypt.ALGORITHM); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptedValue64 = Base64.decode(value, Base64.DEFAULT); byte [] decryptedByteValue = cipher.doFinal(decryptedValue64); String decryptedValue = new String(decryptedByteValue,"utf-8"); return decryptedValue; } private static Key generateKey() throws Exception { Key key = new SecretKeySpec(AESCrypt.KEY.getBytes(),AESCrypt.ALGORITHM); return key; } } 

This will help solve your problem.

+2
source

Send a message The difference between Hashing a Password and Encrypting it I would recommend that you use hashing (without encryption) to store passwords. You can use iemd5 (not recommended), sha1, sha2 ...

Implementation of SHA1 completed: How does SHA1 output a string in Android?

+4
source

Source: https://habr.com/ru/post/1261503/


All Articles