Ozi*_*Ozi 9 encryption passwords android android-studio
有人知道如何加密用户在密码字段中添加的密码吗?
我尝试了这个教程,但我没有得到它的工作.
https://gist.github.com/aogilvie/6267013#file-string_encrypt_decrypt-md
我希望有一个人可以帮助我 :(
小智 12
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;
}
}
Run Code Online (Sandbox Code Playgroud)
使用它将解决您的问题.
引用此帖子Hashing a Password和Encrypting之间的区别 我建议你使用散列(不加密)来存储密码.你可以使用ie md5(不是reccomend),sha1,sha2 ......
示例实现SHA1:如何在Android中对字符串进行SHA1哈希处理?
| 归档时间: |
|
| 查看次数: |
11223 次 |
| 最近记录: |