I can find no sample code to convert a Base64 string to a hexadecimal string, both in the most readable format, such as




Does such an open source library exist? If so, where?

  • 1
    You could ask this question on stackoverflow... better chances of getting best answers to your question. That site's all about programming!
    – mk117
    Commented Jun 29, 2014 at 9:30
  • Does this code help you with the conversion?
    – mk117
    Commented Jun 29, 2014 at 16:55
  • Well, I searched again for "Free libraries" as per your question, and found this library called Crypto++ ... It supports Base64 and Hex conversion, as listed under features...: hex, base-32, and base-64 coding/decoding ... I don't know how it does that, but here's a link to the reference documentation available on that website.
    – mk117
    Commented Jun 29, 2014 at 17:07
  • Done! Answer posted with features and links to download and reference...
    – mk117
    Commented Jun 29, 2014 at 17:29

4 Answers 4


Crypto++® Library 5.6.2

Crypto++ Library is a free C++ class library of cryptographic schemes.

Other features include:

  • pseudo random number generators (PRNG): ANSI X9.17 appendix C, RandomPool
  • password based key derivation functions: PBKDF1 and PBKDF2 from PKCS #5, PBKDF from PKCS #12 appendix B
  • Shamir's secret sharing scheme and Rabin's information dispersal algorithm (IDA)
  • fast multi-precision integer (bignum) and polynomial operations
  • finite field arithmetics, including GF(p) and GF(2^n)
  • prime number generation and verification
  • useful non-cryptographic algorithms
    • DEFLATE (RFC 1951) compression/decompression with gzip (RFC 1952) and zlib RFC 1950) format support
    • hex, base-32, and base-64 coding/decoding
    • 32-bit CRC and Adler32 checksum class wrappers for these operating system features (optional):
    • high resolution timers on Windows, Unix, and Mac OS
    • Berkeley and Windows style sockets
    • Windows named pipes
    • /dev/random, /dev/urandom, /dev/srandom
    • Microsoft's CryptGenRandom on Windows
  • A high level interface for most of the above, using a filter/pipeline metaphor
  • benchmarks and validation testing
  • x86, x86-64 (x64), MMX, and SSE2 assembly code for the most commonly used lgorithms, with run-time CPU feature detection and code selection
    • supports GCC-style and MSVC-style inline assembly, and MASM for x64
  • certain versions are available in FIPS 140-2 validated form



  • Wow, really well-written answer!
    – user5034
    Commented Jun 29, 2014 at 17:29
  • @Cincinnatus Very-well copied it seems – follow the link to see the original. // mk117: copy-pasted content might cause copyright issues, and thus in this form is not very welcome on SE sites. You should always make clear what's a copy and what's your own content. The latter is btw missing in your answer – e.g. personal experience with this product ;)
    – Izzy
    Commented Aug 4, 2014 at 6:02
  • @Izzy lol, I went straight to the manual.
    – user5034
    Commented Aug 4, 2014 at 12:03
  • For me, the "Download" button raised an eyebrow. Then I saw e-sushi's edit (credits to him for detecting the copy-pasta), and knew the reason ;)
    – Izzy
    Commented Aug 4, 2014 at 12:10

Not too sure about doing it in C++ but in python it is easy:

#!/usr/bin/env python

import base64
import binascii

def Print64Hex(instring):
    """ Prints a base 64 string as hex."""
    data = base64.standard_b64decode(instring)
    print binascii.hexlify(data)

if __name__ == "__main__":
    import sys
    for d in sys.argv[1:]:

So if you just need a utility to do this get python, it is also reasonably simple to embed python within your C++ program and vice-versa so using python as a library may be an option for you, see embedding for python 2 or for python3 note that for Python3 you need to change print binascii.hexlify(data) to print(binascii.hexlify(data)) in the code above.


You don't need any 3rd party library if you use Qt:

#include <QByteArray>


QByteArray str1 = "5c2e00405e56439da66a4bd279dbfba2d605d6949142...";
QByteArray hex = QByteArray::fromHex(str1);

QByteArray str2 = "XC4AQF5WQ52makvSedv7otYF1pSRQq3mZM4PxKfO7gqfDF9bihO...";
QByteArray base64 = QByteArray::fromBase64(str2);

QByteArray hexStr = str2.toHex();
  • Just to be sure I’m not mistaking: isn’t Qt – being a framework for C++ and QML – “3rd party” too?
    – e-sushi
    Commented Aug 4, 2014 at 4:30

As an alternative to the already mentioned, potential solutions…

libb64: Base64 Encoding/Decoding Routines

libb64 is a library of ANSI C routines for fast encoding/decoding data into and from a base64-encoded format. C++ wrappers are included, as well as the source code for standalone encoding and decoding executables.

Public Domain.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.