6

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:

U29tZSBEYXRh

I do the following

[byte[]][char[]]"U29tZSBEYXRh"

85
50
57
116
90
83
66
69
89
88
82
104

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?

3
  • 3
    Possible duplicate of How to decode a Base64 string? Commented May 4, 2017 at 7:07
  • Please study the basic idea about Base64 first. Casting b64 into byte-char array doesn't make any sense. Commented May 4, 2017 at 7:09
  • Do you mean "duplicate" or "replicate"? i.e. when you say "This byte array needs to duplicate the bytes...". Commented May 5, 2017 at 5:10

1 Answer 1

11

Use System.Convert.FromBase64String:

[System.Convert]::FromBase64String("U29tZSBEYXRh")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.