java - Why a different key can also decrypt JCE encryptions -
I am confused by JCE, I used some examples and example code to encrypt some text using JCE encryption decryption The technique has tried to decrypt but can either reach a misleading conclusion or remember the whole concept. Indeed, all that I wanted was, by using many well-known algorithms with a human-readable alphanumeric key, Text to encrypt and then he needed to decrypt back with the same key. Here I have given the first example
string text = "Hello world"; String key = "bar 12345kjkj5454hggx1234"; // Create the main key and cipher key ASe = new securcutis (key.getBytes (), "DESede"); Cipher cipher = cipher Get Instances ("DESEDE"); // Cipher.init (cipher NCRVPTMDE, ACK); Byte [] Encrypted = Cipher .Donfonal (text.getbites)); System.err.println ("Use the Triple DES algorithm and convert to & lt;" + key + "& gt;, & lt;" + text + "& gt; with the key & lt;" + New string Encrypted) + "& gt;;) Decrypt text string key 1 =" bar 12345kkkj5454hggx1234 "; // 128 bit key key aesKey1 = new secret (key1.getBytes ()," DESede "); Cipher Cipher 1 = cipher gate instance ("disseed"); cipher1.init (cipher dicraptmoid, ack1); string decrypted = new string (cipher 1.doneine (anchor) Encrypted text & lt; "+ New string (encrypted) +" & gt; System.err.println ("Using Triple DES algorithm and key with & lt;" + key1 + "& gt; ; Decreased & lt; "+ decrypted +" & gt; ";
The deceptive thing is with a different key, I originally used to encrypt the data encrypted using a different key It can be decrypted, it means any type, it should fail if the key supplied for decryption It is not the same to be used for encryption.
Does anyone help me to understand why this is happening and what is the purpose of this algorithm, if we can decrypt the data with the wrong key, then what does security mean? / P>
Thanks in advance! Manish
If I am not mistaken, then it comes from the fact that when you 'k' and 'J' for bytes, bytes, you are only different by your previous bit, and the DES algorithm treats it as a parity bit and pulls it out of the key.
See
To demonstrate what happens, try this code:
secret activityfactor kf = SecretKeyFactory.getInstance ("DESede"); Adjust the parity of the secret = kf.generate (newDesdKSPEC (AESKEGet encoded ()); Secret Equality Adjust 1 = kf.generateSecret (new DEDESPEC (aesKey1.getEncoded ())); System.out.println (new string (parity adjusted .gate encoded ()); System.out.println (new string (parity adjusted 1.gate encoded ());
The output will be:
Cas12244kkkk4444hggy1224 Cas12244kkkk4444hggy1224
As you do See, after the equality adjustment, both keys are essentially the same key.