Quantcast
Viewing all articles
Browse latest Browse all 4

Convert a hex string to base64

byte[] ba = Encoding.Default.GetBytes(input);
var hexString = BitConverter.ToString(ba);
hexString = hexString.Replace("-", "");
Console.WriteLine("Or: " + hexString + " in hexadecimal");

So I got this, now how would I convert hexString to a base64 string?
I tried this, got the error:

Cannot convert from string to byte[]

If that solution works for anyone else, what am I doing wrong?

edit:

 var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(plainText);
 return System.Convert.ToBase64String(plainTextBytes);

I tried this, but it returns "Cannot implicitly convert type 'byte[]' to 'string'" on the first line, then "Argument 1: cannot convert from 'string' to 'byte[]'".


Viewing all articles
Browse latest Browse all 4

Trending Articles