Using java to encrypt integers

后端 未结 7 1501
野性不改
野性不改 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:09

    My Simple Solution is that Encrypt Integer to the String by shifting ASCII Value of the Integer by the secret key you Provide.

    Here is the Solution:

    public String encodeDiscussionId(int Id) {
    
        String tempEn = Id + "";
        String encryptNum ="";
        for(int i=0;i

    Steps to Encode:

    1. Here, First you convert the Given Integer into String by: String temp = givenInt + ""
    2. Scan each character of String, Read ASCII of that character and add it with secret key as 148113 in this case.
    3. Convert shifted Integer into Character and concatenate to the String encryptNum and finally return it.

    Steps to Decode:

    1. Scan each character of String, Read ASCII of that character and subtract it with secret key as previous.
    2. Convert that value to character and concatenate with decodeText.

    As previous encode output is always String '???' and vary according to number of digits of input Id.

提交回复
热议问题