Convert Base64 string to byte array in .NET (or PowerShell)

Question:

I am working with a Linux guy at work (I work on Windows). He sends me a base64 string which I need to turn into a byte array using PowerShell. This byte array needs to duplicate the bytes he originally started with (he is using Phyton).

So basically, he takes some data and converts it to base64 string, then I need to take the base64 string and convert back to bytes so we end up with the same bytes. (As latter I need to check a signed digest of these bytes, not relevant for now.)

Therefore, let us say he sends me the following base64 string:

I do the following

but he says my output is an ASCII code representation of the string and not the actual bytes (he thinks the bytes should be returned as non-sense to the screen e.g. unprintable characters as it were).

Am I getting a genuine byte array of the input data or not?

Answer:

Use System.Convert.FromBase64String:

Source:

Convert Base64 string to byte array in .NET (or PowerShell) by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply