Raghu Sitarama wrote:
I am having the exact same problem and trying to figure out what is going wrong.
Could you please explain or post how you solved it?
Should the input string (encrypted string for decrypting) be "handled" in the sense padded up?
how do I pad up an encrypted string before decryption? Is it a problem with the key padding or the string length.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Raghu Sitarama wrote:Thanks James.
I am sorry, if I was cryptic there.
I am writing my code in java.
I am having basically 2 problems. one is key generation and the second one is getting the desede to work (decrypt an encrypted string). It is a Password based encryption (I think you can call it so). Basically there is a plain text string (like a password) that the calling application and my application knows. the calling application uses the plain text string and generates a 168 bit key and then uses that to to do a DESede/CBC/PKCS5Padding encryption and send that encrypted information over and my application using the same plain text string should generate my key and then use that to decrypt that information and use that information for further processing.
problem 1: key generation. The other application is a windows / .net based and they are using CryptDeriveKey function from Microsoft based provider. My application is a java servlet and Oracle App Server (so a fully java env). possibly we have the sun based provider. So, I did a lot of study and finally did my own implementation of CryptDeriveKey in java using the same algorithm but implemented in java. (basically takes the SHA-1 digest of the plain text string and then do the array filling with particular bits with XOR bit operation etc. etc.) I am not getting into the details of that here for brevity. But got a 168 bit (21 bytes) key as desired.
Now my first problem here was getting that 168 bit key to work with my DESede code. it would complain as InvalidKeyException. because it was expecting 24 bytes (I don't know why)
but neglecting the parity bits. But because, I am not using the standard key generator and defining my own key and defining a keyspec etc. there was some issue there and it was complaining. so, I was told to massage the key and add the parity bits. I then wrote the method to carefully add the 8th parity bits (luckily some gracious good programmer had put up a nice code to add this for DES keys on the net). Now, the key is going through, but the cipher do final is creating problems. I am pasting my code for the key generation as well as for the decryption.
problem 2: decryption. I am having problems here and would love help. I am attaching the code below. the encrypted string is some funky looking string with characters of all shapes how do I do the padding of it? also, I have already specified PKCS5Padding in the algorithm spec. isn't that supposed to do the padding?
why is it expecting the input string to be exactly 8 byte blocks?
now, I tried the cipher.update() method and did a println before I did the cipher.doFinal() as the doFinal was what was throwing the IllegalBlockSizeException. but could not figure if the intermediate output was ok. Basically need help here.
Key generation code:
Decryption code:
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
This tiny ad is wafer thin:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|