Encrypt an integer value with DES


I want to encrypt an integer with DES, the resultant cipher text should also be an integer.

Decryption function should follow this notion as well.

I am trying to modifying the code at Encrypting a String with DES, by converting the byte array to integer, instead of using Base64 encoding. However the decryption function throws an exception of improper padding, as the conversion of integer to byte[] results in a 4 byte array.

Is there any other encryption algorithm that I can use to achieve this.

  • I am not concerned about the weakness of the cipher text.

If you are running an Integer value through DES to produce another Integer value, and you don't care about the cipher text weakness, then you are merely doing a very expensive hashing operation. You'd be better off generating a random integer as the key and bitwise xor-ing the exponent and the random integer. This would take nanoseconds to compute and have exactly the same security.