Base64 Encode/Decode compatible with openssl EVP_Decode/Encode

From: Ramy076 (ramy076_at_yahoo.com)
Date: 04/01/04


Date: 1 Apr 2004 03:47:09 -0800

I have a C App which uses openssl for Encoding and decoding which
needs to be ported to java.

The decoded text does not match between the C App and the java App.
The size of the output itself is wrong. I think i am doing something
basically wrong. pls help.

Output is not the same as seen here because of special characters
Output from C: is only 12 bytes long

m.~..u_.7u...`.K.|dR..H?..}..o

Output from Java: 128 bytes including a new line char.

+mtn+O~+?
f8u-_?f-7u???`?K?|dR?H?+?v?}d?o-QxDSG-?'u?H1Fz8|}1~-Hw-f?}~-__i
+HAGaB?_~?uv??|D

Following is the code in both C and Java
C Code:

char* my = new char(172);
char base64[78];
int x;
int keyLength;
EVP_ENCODE_CTX ctx;

getbaseData()
{
        memset(my,0,172);
        strcpy(my,"1234567899adserffsgbhgrthfbsdferwsdfghjtyjf+dfgDGRdgHEsdfGRSGH+ASD/FG/sdfesfgW/SFVGHeERT4sEYJ5+sdfERSDFGesfsfJTdfTGJfsSfSHfEZpsdfa36fsJf3sdfaSDFSEFHYUKMF5dfftsadfsd+asffES=");
        EVP_DecodeInit(&ctx);
        EVP_DecodeUpdate(&ctx, (unsigned char *)base64, &x, (unsigned char *)
my, 172);
        keyLength = x; //getting 48
        EVP_DecodeFinal(&ctx, (unsigned char *)&base64[x], &x);
        keyLength += x; //getting 12
}

Java Code used the Base64 code from
http://ostermiller.org/utils/Base64.html i also tried the B64 class
from http://sourceforge.net/snippet/detail.php?type=snippet&id=100549
- both the results are the same.

java com.Ostermiller.util.Base64 -vd
1234567899adserffsgbhgrthfbsdferwsdfghjtyjf+dfgDGRdgHEsdfGRSGH+ASD/FG/sdfesfgW/SFVGHeERT4sEYJ5+sdfERSDFGesfsfJTdfTGJfsSfSHfEZpsdfa36fsJf3sdfaSDFSEFHYUKMF5dfftsadfsd+asffES=



Relevant Pages

  • Re: Native gem roundup!
    ... (I'm not too familiar with Java GUI frameworks)... ... Monkeybars app - http://monkeybars.rubyforge.org/) by default on Macs ... Java) or JotBot (http://getjotbot.com/ - JRuby with Monkeybars) ... I brought up RubyCocoa not because I thought it would be ...
    (comp.lang.ruby)
  • Re: POSSIBLE SECURITY PROBLEM in Java 5!
    ... still worked -- but the network activity dropped to zero and it ... Naturally, suspecting a bug, I exited and went to rerun the app, this ... Task Manager showed two Java tasks, ... and killing it should have released the sockets. ...
    (comp.lang.java.programmer)
  • Re: Java on the BSD Desktop?
    ... interactivity we must also put into disscusion Adobe Flash and Adobe Flex ... To my oppinion Java is more suitable for back end solutions. ... I would like to see a native FreeBSD Flash player. ... > First off, in my company we had a Java app (simple app, working with ...
    (freebsd-questions)
  • POSSIBLE SECURITY PROBLEM in Java 5!
    ... still worked -- but the network activity dropped to zero and it ... Naturally, suspecting a bug, I exited and went to rerun the app, this ... Task Manager showed two Java tasks, ... and killing it should have released the sockets. ...
    (comp.lang.java.programmer)
  • Re: My OPE & the Euclicidean TSP
    ... path algorithm pop up, prove that P=NP, and solve TSP through the use ... Any idea the effort involved to get an app ... been on major Java coding project from inception to product release as ... I like mentioning Class Viewer because it's great for perspective ...
    (comp.lang.java.programmer)