开发者

Encrypt an Integer Value with DES

开发者 https://www.devze.com 2023-03-26 09:39 出处:网络
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 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 Strin开发者_运维技巧g 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.


DES has a 64 bit blocksize, so in general the output from the encryption of a 32 bit int will be a 64 bit block. It will be easier to encrypt a 64 bit long to another 64 bit long. Use ECB mode so that padding is not an issue, or at least you are adding zero bits to the front of your int to extend it to 64 bits.

If you merely want to smush up your int then Jim's suggestion is excellent.


You want to look at Format Perserving Encryption. There are a couple of techniques for it, but in general all of them will generate a value in the same domain as your input ( i.e. integers, credit card numbers,etc)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号