inzaghi
asked on
base64 decoding
I am using the import w3c.tools.codec.Base64Deco der;
to decode a base64 string, the method
new Base64Decoder(base64string ).processS tring() returns a string object I need a byte representation of this data.
Is it correct to assume that we jsut need to call getBytes() at the end?
to decode a base64 string, the method
new Base64Decoder(base64string
Is it correct to assume that we jsut need to call getBytes() at the end?
Yes. YOu must ask for thre correct encoding though
ASKER
Will I still need to do this even if when I open the file for reading the data from as
br = new BufferedReader( new InputStreamReader( f, "UTF-8)) );
String str = br.readLine();
String decode = new Base64Decoder(str.processS tring();
byte[] b = decode.getBytes();
br = new BufferedReader( new InputStreamReader( f, "UTF-8)) );
String str = br.readLine();
String decode = new Base64Decoder(str.processS
byte[] b = decode.getBytes();
ASKER
oops this refers to
>>Yes. YOu must ask for thre correct encoding though
>>Yes. YOu must ask for thre correct encoding though
Can you remind me how you've *written* the atoms?
ASKER
username + \u241e + encrypteddata
I have tokenized the string based on the u241e
and to get the encypteddata back into byte data I have done the above ( i haven't shown the full solution above though)
I have tokenized the string based on the u241e
and to get the encypteddata back into byte data I have done the above ( i haven't shown the full solution above though)
>>( i haven't shown the full solution above though)
Well that's what's confusing me! Can you do so (and repeat what your quesition is ;-))?
Well that's what's confusing me! Can you do so (and repeat what your quesition is ;-))?
When i say 'the full solution' i mean the full code for handling that part of the reading back of course
ASKER
br = new BufferedReader( new InputStreamReader( f, "UTF-8)) );
while (str = br.readLine!=null){
StringTokenizer st = new StringTokenizer(str, " \u241e");
String user= st.nextToken();
String base64 = st.nextToken();
String decodedS = new Base64Decoder(base64).proc essString( );
byte[] b = decodedS.getBytes("UTF-8") ;
} }
while (str = br.readLine!=null){
StringTokenizer st = new StringTokenizer(str, " \u241e");
String user= st.nextToken();
String base64 = st.nextToken();
String decodedS = new Base64Decoder(base64).proc
byte[] b = decodedS.getBytes("UTF-8")
} }
In what way does processString work (i don't know the class)?
Forget that - i checked it. No - that call won't do as you originally had an encrypted byte array there, not a String, as far as i can remember
ASKER
sorry 4 the late reply,
I am trying to get the original encrypted byte array.
Originall the byte array was encoded to base64.
I know need to decode it and get the bytes.
Dont understand why the following will not work?
String decodedS = new Base64Decoder(base64).proc essString( );
byte[] b = decodedS.getBytes("UTF-8") ;
I am trying to get the original encrypted byte array.
Originall the byte array was encoded to base64.
I know need to decode it and get the bytes.
Dont understand why the following will not work?
String decodedS = new Base64Decoder(base64).proc
byte[] b = decodedS.getBytes("UTF-8")
ASKER
The actual string consists
of the username + seperator + encryptedData
The encrypted data is a byte array which has been encoded using base64
I don't understand why
String decodedS = new Base64Decoder(base64).proc essString( );
byte[] b = decodedS.getBytes("UTF-8") ;
will not work?
of the username + seperator + encryptedData
The encrypted data is a byte array which has been encoded using base64
I don't understand why
String decodedS = new Base64Decoder(base64).proc
byte[] b = decodedS.getBytes("UTF-8")
will not work?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks objects, but why wont this work
String decodedS = new Base64Decoder(base64).proc essString( );
byte[] b = decodedS.getBytes("UTF-8") ;
String decodedS = new Base64Decoder(base64).proc
byte[] b = decodedS.getBytes("UTF-8")
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> Thanks objects, but why wont this work
Cause there is additional encoding involved in converting between byte arrays and Strings which will corrupt your data.
Cause there is additional encoding involved in converting between byte arrays and Strings which will corrupt your data.
8-)
Regards