Conversion between Base64String and Hexadecimal

22,794

FromBase64String will take the string to bytes

byte[] bytes = Convert.FromBase64String(string s);

Then, BitConverter.ToString() will convert a byte array to a hex string ( byte[] to hex string )

string hex = BitConverter.ToString(bytes);
Share:
22,794
Aan
Author by

Aan

I need to learn more & more.

Updated on April 15, 2020

Comments

  • Aan
    Aan about 4 years

    I use in my C++/CLI project ToBase64String to give a string like /MnwRx7kRZEQBxLZEkXndA== I want to convert this string to Hexadecimal representation, How I can do that in C++/CLI or C#?

  • bryanmac
    bryanmac over 12 years
    I think the unicode.getbytes will treat that string as unicode chars when what you want is for the conversion to treat them as Base64. I think Convert.FromBase64String() does exactly that ...
  • Mohsin Khan
    Mohsin Khan over 3 years
    hex.Replace("-", "").ToLower(); This line is so important