The difference between winner and loser is making things happen and letting things happen.
William Frederico<br />Logic Mountain Software<br /><a href="http://www.logicmountain.com" target="_blank" rel="nofollow">http://www.logicmountain.com</a>
In Theory, there is no difference between theory and practice.<br />In Practice, there is no relationship between theory and practice.
I have tried converting the ChiperText String to bytes using the Base64Decoder
Serch Hdez wrote:Hello I'm facing the same problem and so far I could have not found any solution to come around it, I tried getting the char array from the string and then converting to byte each char from it but I get the same result, I also try the BASEDecoder algorithm but it's the same, I'm saving the bytes I'm getting into a file using the FileOutputStream and then the FileInputStream, but everytime I read the password from the file I get the error, has anyone found a way to do this?.. the code works as long as you encrypt and decrypt using the very same string, but once I store the bytes and try to retrieve those I get the error.. please help.. thanks.
Regards.
Nice to meet you.
strEncryptedText = new String(result);
Ulf Dittmer wrote:
strEncryptedText = new String(result);
This is wrong. You simply can't convert a byte[] that holds binary data into a String. If you need to treat a byte[] as String (why?), run it through base-64 or something similar.
Ulf Dittmer wrote:You're using different keys for encryption and decryption. "generateKey" create a random key, which will be different each time.
Also, don't use "DES" as the cipher, use "DESede". DES is obsolete these days, but Triple-DES (a.k.a. DESede) is still OK to use.
Trey Howard wrote:Regarding the earlier comment 'create your own byte array conversion function', I thought I'd share a solution I found in the hopes of saving others some time and trouble.
You case use BASE64Encoder and BASE64Decoder (sun.misc package classes provided by JDK) to convert between String and byte[].
For example:
where the byte[]s are equal.
HTH
-Trey
It's a tiny ad. At least, that's what she said.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|