Using java to encrypt integers

后端 未结 7 1592
野性不改
野性不改 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 14:54

    create a 4-byte array and copy the int to the array in 4 steps, with bitwise ANDs and bitshifting, like Paulo said.

    But remember that block algorithms such as AES and DES work with 8 or 16 byte blocks so you will need to pad the array to what the algorithm needs. Maybe leave the first 4 bytes of an 8-byte array as 0's, and the other 4 bytes contain the integer.

提交回复
热议问题