Closed masaoliou closed 12 months ago
Can you please be more specific. What exactly does not compatible?
Can you show an example of what b64url creates and what do you expect?
#include <cppcms/base64.h>
#include <sstream>
#include <iostream>
int main()
{
const std::string s("This is John Smith.");
std::ostringstream os;
cppcms::b64url::encode(reinterpret_cast<const unsigned char*>(s.c_str()),reinterpret_cast<const unsigned char*>(s.c_str())+s.size(),os);
std::cout << os.str() << std::endl; //VGhpcyBpcyBKb2huIFNtaXRoLg
std::cout << "=?utf-8?B?" << os.str() << "?=" << std::endl; //=?utf-8?B?VGhpcyBpcyBKb2huIFNtaXRoLg?=
return 0;
}
This web page can't decode the last string =?utf-8?B?VGhpcyBpcyBKb2huIFNtaXRoLg?=
following "Subject: ".
The following shell command
echo -ne "This is John Smith." | base64
gives the following string:
VGhpcyBpcyBKb2huIFNtaXRoLg==
The aforementioned web page properly decodes the following string after "Subject: ":
=?utf-8?B?VGhpcyBpcyBKb2huIFNtaXRoLg==?=
I explain, there is difference between base64 and base64url
https://en.wikipedia.org/wiki/Base64#Variants_summary_table
Short summary:
+
and /
characters while base64url uses -
and _
=
and does not require new linesYou are confusing two very similar but different encodings - the code you linked to is actually base64 and not base64url.
I have tested on https://dogmamix.com/MimeHeadersDecoder and https://www.base64encode.org and have found that cppcms::b64url::encode() seems to be incompatible with https://datatracker.ietf.org/doc/html/rfc2047.txt
This implementation works as expected.
Any idea?