Android: Encrypt a string with AES 256bit Encryption with iv and secret key

后端 未结 2 842
无人及你
无人及你 2020-12-30 18:03
SecureRandom random = new SecureRandom(); // quite heavy, look into a lighter method.

String stringToEncrypt = \"mypassword\";
byte[] realiv = new byte[16];
random.         


        
2条回答
  •  孤独总比滥情好
    2020-12-30 18:50

    I strongly suspect that what you want to do is call ecipher.doFinal(stringToEncrypt), possibly after a series of doUpdate(...) if you have longer strings.

    .init() creates the cipher object, update() and doFinal() populate the encrypted output and take the plaintext as input.

    Of course, you'll need to convert between String and a byte array.

提交回复
热议问题