Convert between Base64String and Hex

I use C ++ / CLI in my project ToBase64Stringto give a line similar /MnwRx7kRZEQBxLZEkXndA==. I want to convert this string to hexadecimal representation. How can I do this in C ++ / CLI or C #?

+5
source share
2 answers

FromBase64String will take stringto bytes

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

Then BitConverter.ToString()converts the byte array to the sixth string ( byte [] into a hexadecimal string )

string hex = BitConverter.ToString(data);
+18
source

Convert a string to an array of bytes, and then convert the byte to hexadecimal

string stringToConvert = "/MnwRx7kRZEQBxLZEkXndA==";

byte[] convertedByte = Encoding.Unicode.GetBytes(stringToConvert);

string hex = BitConverter.ToString(convertedByte);

Console.WriteLine(hex);
+1

All Articles