We have found some inconsistencies with the Base 64 Decoding.
Here is what happens:
the base64 encoding of "a" is "YQ=="
When we decodeUpdate using the whole string "YQ==" we get
back "a" which is a string of length 1.
When we decodeUpdate several times, depending on how we break the string
"YQ==" we get two answers:
1) "a" which is a string of length 1
update "YQ"
update "=="
2) "a\0" which is a string of length 2
update"YQ="
update"="
or
update"YQ"
/* sample code below */
update"="
update"="
Now in C++ this makes a big problem because the string is not null terminated.
The length does matter.
And we cannot just remove the null from the end result because it may
have been part of the original string.
Could u please look into this?
Also It looks to me that EVP_DecodeFinal is a no call.
It does not seem to do anything. I have called it with
"a", "aa", "aaa", "aaaa", .....,"aaaaa..." (1000 a's)
So are there cases where it actually does anything?
Thanks. This we can live with. The first problem we can't.
typedef unsigned char * UcPtr;
{
EVP_ENCODE_CTX ctx;
char buf[10];
int total = 0;
int len;
EVP_DecodeInit(&ctx);
char *enc;
enc = "YQ==";
EVP_DecodeUpdate(&ctx, (UcPtr) buf, &len, (UcPtr) enc,
4);
total += len;
EVP_DecodeFinal(&ctx, (UcPtr) buf, &len);
total += len;
cout << "total = " << total <<
endl;
/* here total = 1: "a" is the result */
}
{
EVP_ENCODE_CTX ctx;
char buf[10];
int total = 0;
int len;
EVP_DecodeInit(&ctx);
char *enc;
enc = "YQ";
EVP_DecodeUpdate(&ctx, (UcPtr) buf, &len, (UcPtr) enc,
2);
total += len;
enc = "=";
EVP_DecodeUpdate(&ctx, (UcPtr) (buf + total), &len,
(UcPtr) enc, 1);
total += len;
enc = "=";
EVP_DecodeUpdate(&ctx, (UcPtr) (buf + total), &len,
(UcPtr) enc, 1);
total += len;
EVP_DecodeFinal(&ctx, (UcPtr) (buf + total), &len);
total += len;
/* here total = 2: "a\0" is the result */
}
-- Abdelilah Essiari [EMAIL PROTECTED] Lawrence Berkeley National Laboratory work (510) 495-2872 1 Cyclotron Rd. Home (510) 893-4578 Berkeley, CA 94702