开发者

Decryption of different keys give the same result

开发者 https://www.devze.com 2023-01-06 19:29 出处:网络
I saw this behavior today while working with a Java EE Framework. Every time I\'m getting an int ID from the server, that ID is encrypted + encoded in base 64, and the encrypted string is sent back. E

I saw this behavior today while working with a Java EE Framework. Every time I'm getting an int ID from the server, that ID is encrypted + encoded in base 64, and the encrypted string is sent back. Each request gives a different encrypted key. The behavior that is strange is that if I make 5 requests, the encrypted text I received aft开发者_开发知识库er the first request still works (decrypting it will give me the right int ID). The encryption works something like this:

   request 1 for (same) ID => 
     int ID + salt + ?(assume unique timestamp) = encrypted text 1 => encoded result 1
   request 2 for (same) ID => 
     int ID + salt + ?(assume unique timestamp) = encrypted text 2 => encoded result 2

My question is: without caching anything (test it on two different stations, different encryption strings for same number will decrypt to same number on both stations), how is this behavior possible, in the sense that how does the decryption algorithm know how to map from many 12-character encrypted strings to the same initial data? IN addition, is there a limitation on how many encrypted strings one can have that would map to the same data?

Thanks!

P.S.The Framework, which is open source, uses the javax.crypto.Cipher.doFinal method for both encryption and decryption.


Many encryption modes use an initialization vector to randomize the ciphertext. If you use such an encryption mode, then encrypting the same plaintext twice results in different ciphertexts and decrypting them will result in the same plaintext again.

To answer all your questions it would be necessary to have more details about the encryption mode that you use.

0

精彩评论

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