Base 64 URL Decoding Wtih Base64Decoder?

22 views
Skip to first unread message

hc12...@gmail.com

unread,
Apr 3, 2018, 11:46:00 PM4/3/18
to Crypto++ Users
Hi,

I noticed that Base64URLDecoder exists but unfortunately, I am stuck with 5.6.2, which doesn't have it.

So I followed the recommendation on https://www.cryptopp.com/wiki/Base64Decoder (Changing Alphabets section):

// my code snippet
        std::string decoded_key;

        const byte ALPHABET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
        int lookup[256];
        CryptoPP::Base64Decoder::InitializeDecodingLookupArray(lookup, ALPHABET, 64, false);

        try
        {
                CryptoPP::Base64Decoder* pDecoder = new CryptoPP::Base64Decoder();
                pDecoder->IsolatedInitialize(CryptoPP::MakeParameters(CryptoPP::Name::DecodingLookupArray(),(const int *)lookup));
                pDecoder->Attach(new CryptoPP::StringSink(decoded_key));
                // Decode the key since it is base64url encoded
                CryptoPP::StringSource src(key, true, pDecoder);


But then I got an exception:
AlgorithmParametersBase: parameter "DecodingLookupArray" not used

Am I missing something?

Thanks in advance!

Jeffrey Walton

unread,
Apr 4, 2018, 2:48:18 AM4/4/18
to Crypto++ Users


On Tuesday, April 3, 2018 at 11:46:00 PM UTC-4, hc12...@gmail.com wrote:
Hi,

I noticed that Base64URLDecoder exists but unfortunately, I am stuck with 5.6.2, which doesn't have it.

It can be available in all versions of the library. Just copy/paste it from the existing sources :)
 
So I followed the recommendation on https://www.cryptopp.com/wiki/Base64Decoder (Changing Alphabets section):

// my code snippet
        std::string decoded_key;

        const byte ALPHABET[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
        int lookup[256];
        CryptoPP::Base64Decoder::InitializeDecodingLookupArray(lookup, ALPHABET, 64, false);

        try
        {
                CryptoPP::Base64Decoder* pDecoder = new CryptoPP::Base64Decoder();
                pDecoder->IsolatedInitialize(CryptoPP::MakeParameters(CryptoPP::Name::DecodingLookupArray(),(const int *)lookup));
                pDecoder->Attach(new CryptoPP::StringSink(decoded_key));
                // Decode the key since it is base64url encoded
                CryptoPP::StringSource src(key, true, pDecoder);


But then I got an exception:
AlgorithmParametersBase: parameter "DecodingLookupArray" not used

Not sure why you are catching the exception but...

You can add false as a thid parameter to avoid the exception:

    MakeParameters(Name::DecodingLookupArray(),(const int *)lookup), false);

I'm not sure what trouble you might encounter afterwards, like failure to change the alphabet or changing the alphabet for all decoders.

In the end, I recommend the copy/paste method to get it.

Jeff

Henry Chan

unread,
Apr 5, 2018, 4:29:43 AM4/5/18
to Jeffrey Walton, Crypto++ Users
Yeah, I did try to set the 3rd parameter to false to suppress the exception.

Tho, I am having trouble to get the correct hashed string (I didn't paste that part of the code, which depends on the decoded string); and I wonder it has something to do with my usage of Base64Decoder, and the exception caught my attention...

Yes, I guess I will just copy and paste the class if nothing else I can find.

Thanks for your input :)

--
You received this message because you are subscribed to "Crypto++ Users". More information about Crypto++ and this group is available at http://www.cryptopp.com and http://groups.google.com/forum/#!forum/cryptopp-users.
---
You received this message because you are subscribed to a topic in the Google Groups "Crypto++ Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cryptopp-users/fe3xWRw_Uso/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cryptopp-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages