473,714 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Base64 Encode/Decode compatible with openssl EVP_Decode/Encode

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ýýýý_ý.ý ý7ýuý...`.K.|dR ..ýH?ý.ý.}ý..oý
Output from Java: 128 bytes including a new line char.

+mýtýný+ýýOý~+? ý
fýý8uýý-ý_ý?f-7ýuý???`?K?|dR? ýýH?+?v?}d?ýo-ýQýxDSG-?'ýýuý?H1Fzý8|ý ý}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,"1234 567899adserffsg bhgrthfbsdferws dfghjtyjf+dfgDG RdgHEsdfGRSGH+A SD/FG/sdfesfgW/SFVGHeERT4sEYJ5 +sdfERSDFGesfsf JTdfTGJfsSfSHfE Zpsdfa36fsJf3sd faSDFSEFHYUKMF5 dfftsadfsd+asff ES=");
EVP_DecodeInit( &ctx);
EVP_DecodeUpdat e(&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/detai...ppet&id=100549
- both the results are the same.

java com.Ostermiller .util.Base64 -vd
1234567899adser ffsgbhgrthfbsdf erwsdfghjtyjf+d fgDGRdgHEsdfGRS GH+ASD/FG/sdfesfgW/SFVGHeERT4sEYJ5 +sdfERSDFGesfsf JTdfTGJfsSfSHfE Zpsdfa36fsJf3sd faSDFSEFHYUKMF5 dfftsadfsd+asff ES=
Jul 17 '05 #1
0 4223

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
16204
by: Schneider Alexander | last post by:
Hello, I would to encode and respectively to decode string's. Now ist my question: Is there a Funktion into J2SE 1.4 API? Thanks Alexander Schneider
1
8102
by: Oliver Kurz | last post by:
Hello, I have a problem by converting a string to base64 and back again. I have a string with german special chars like äöüß. This string i convert with base64str=base64.encode('äöüß') into a base64 representation. Backwards I got an error:
1
2219
by: Damir Hakimov | last post by:
Hi *! I found a strange bug in base64.encode and decode, when I try to encode - decode a file 1728512 bytes lenth. Is somebody meet with this? I don't attach the file because it big, but can send to private. Which solution for transfer file (binary data) via string-only object? Damir.
4
5358
by: John | last post by:
Hi all, I've been going through google and yahoo looking for a certain base64 decoder in C without success. What I'm after is something that you can pass a base64 encoded string into and get back a decoded String. Any help is very much appreciated. Thanks Philip.
3
4098
by: Guoqi Zheng | last post by:
Dear sir, I need to decode base64 encoded email. I used below function but it does not work correctly, especially when I need to decode some Characters like Chinese, Can some one point out what I did wrong here? Thanks.
5
4117
by: Jay | last post by:
I have bean trying to get my head around reading .GIF files from base64 strings, Basically I need to specify a filename and convert it to base64 then I can copy/past the string to wear I want it. Cold somebody check this for me to see what I have done wrong: If you run this program and enter a path for a .GIF file into the white box and hit <Enter> it should display the string in the blue box. To test this if you click the menu File...
13
14780
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or send me the library file which helps that is really grateful. aruna.
10
4050
by: pycraze | last post by:
Hi , I am currently trying to implement base64 encoding and decoding scheme in C . Python has a module , base64 , that will do the encoding and decoding with ease . I am aware of OpenSSL having support for base64 encoding and decoding , but i will have to now implement both in C without using the openssl libraries . I was able to download a code w.r.t. base 64 encoding and decoding . I am attaching the code below .
3
3787
by: d-fan | last post by:
void decodebio( unsigned char *encbuf, unsigned char * decbuf, int destbuf ) { /* Read Base64 encoded data from standard input and write the decoded data to standard output: */ BIO *b64, *bio ; long i ; char buffer ; memset(buffer, 0, 512) ;
0
8704
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3155
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.