Using java to encrypt integers

后端 未结 7 1602
野性不改
野性不改 2021-02-03 14:14

I\'m trying to encrypt some integers in java using java.security and javax.crypto.

The problem seems to be that the Cipher class only encrypts byte arrays. I can\'t d

7条回答
  •  不要未来只要你来
    2021-02-03 15:04

    Just use:

        Integer.toString(int).getBytes();
    

    Make sure you use your original int and getBytes() will return a byte array. No need to do anything else complicated.

    To convert back:

        Integer.parseInt(encryptedString);
    

提交回复
热议问题