android - 如何加密我的密码 - Android Studio

标签 android android-studio encryption passwords

有人知道如何加密用户在密码字段中添加的密码吗?

我尝试了本教程,但没有成功。

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

我希望有人能帮助我:(

最佳答案

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;
    }
}

使用它可以解决您的问题。

关于android - 如何加密我的密码 - Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41223937/

相关文章:

android - 无法解析符号卡,android studio 中的依赖错误

android - 将 Android POST 数据从 Packet Capture 应用程序保护到 Web 服务器 API

android - 获取歌曲的所有声音字节以用于Android应用

android - Xamarin 在启动应用程序时形成 ActivityIndi​​cator

java - 从 RecyclerAdapter 使用异步任务时出错

android - 如何在Android Studio中集成pullToRefresh

Azure Web 应用程序文件加密

Caesar Cipher C 程序未正确加密

android - 主题级别的 RecyclerView 样式

android - Android 中 ArrayAdapter 中的 CheckBox 和 TextView