Your Order for encrypt: getBytes, encrypt, encode, toString Your Order for decrypt: getBytes, decrypt, decode, toString.
Your Order for encrypt: getBytes, encrypt, encode, toString Your Order for decrypt: getBytes, decrypt, decode, toString Two problems: As someone already mentioned you should reverse the order of operations. You are not doing that. Encrypt gives you 16 bytes, encode 24 bytes, but toString gives 106 bytes.
Something to do with invalid chars taking up additional space. Note: Also, you don't need to call generateKey() twice. Fix problem #1 by using the reverse order for decryption.
Correct order: getBytes, decode, decrypt, toString Fix problem #2 buy replacing xxx.toString() with new String(xxx). Do this in both the encrypt and decrypt functions. Your decrypt should look like this: c.
Init(Cipher. DECRYPT_MODE, key) val decodedValue = new Base64(). Decode(encryptedValue.getBytes()) val decryptedVal = c.
DoFinal(decodedValue) return new String(decryptedVal) This should give you back "dude5.
Fundamentally, there is an asymmetry between your encrypt function and your decrypt function. When you encrypt you perform an AES encrypt and then a base64 encode, when you decrypt you don't first undo the base64 encoding step. I think that there's something wrong with your base64 encoding as well as shouldn't appear in a base64 encoded string.
Looking at the documentation for org.apache.commons.codec.binary. Base64 you should be able to do this on encode: String encryptedValue = Base64. EncodeBase64String(encValue); and this on decode: byte encValue = Base64. DecodeBase64(encryptedValue).
Commons.apache. Org/codec/apidocs/org/apache/commons/codec/… – Charles Bailey Oct 18 '10 at 5:16.
The line String encryptedValue = encryptedByteValue.toString(); is the problem. The type of encryptedByteValue is byte and calling toString on it isn't what you want to do there. Instead try String encryptedValue = Base64.
EncodeToString(encValue); Then use Base64. DecodeBase64(encryptedValue) in decrypt. You must do that prior to attempting to decrypt though. You must undo the operations in the reverse order of the encrypt method.
Its just add there to return a String from the method..also in Base64 there is no such method encodeToString – Harshana Oct 18 '10 at 1:22 Regarding the toString, calling that method on an Array is almost never what you want to do. It returns the address in memory of the object, not a useful String representation. Regarding Base64, aren't you using this?
Commons.apache.Org/codec/apidocs/org/apache/commons/codec/… See the method here: commons.apache. Org/codec/apidocs/org/apache/commons/codec/… – laz Oct 18 '10 at 3:07 ive put commons-codec-1.2 and also try 1.3 jar but seems that method is not display know.. – Harshana Oct 18 '10 at 6:48 It is in commons-code 1.4 according to that Javadoc I linked to. – laz Oct 18 '10 at 13:42.
I downloaded 1.5 from the apache site and while it says in the documentation that these methods exist, they don't show up when you do code completion and they create an unknown method when you provide them. I was able to do: byte raw = md.digest(); //step 4 byte hashBytes = Base64. EncodeBase64(raw); //step 5 StringBuffer buffer = new StringBuffer(); for( int i=0; iI don't think this is the "right" way to do things, but can't find the methods that the documentation says are there.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.