How can I encrypte my password - Android Studio

前端 未结 3 812
半阙折子戏
半阙折子戏 2021-02-02 17:57

does someone know how to encrypte the password which the user add`s into the password field?

I tried this tutorial but I didn\'t get it work.

https://gist.githu

3条回答
  •  情歌与酒
    2021-02-02 18:48

    This is the easiest solution ever existed for normal encryption. First, add this in your build gradle file:

        implementation 'com.scottyab:aescrypt:0.0.1'
    

    Then use the bellow code for encryption and decryption:

    // To Encrypt
    String password = "password";
    String message = "hello world";	
    try {
        String encryptedMsg = AESCrypt.encrypt(password, message);
    }catch (GeneralSecurityException e){
        //handle error
    }
    
    // To Decrypt
    String password = "password";
    String encryptedMsg = "2B22cS3UC5s35WBihLBo8w==";
    try {
        String messageAfterDecrypt = AESCrypt.decrypt(password, encryptedMsg);
    }catch (GeneralSecurityException e){
         //handle error - could be due to incorrect password or tampered encryptedMsg
    }

提交回复
热议问题