I have a Base64 byte[]
array which is transferred from a stream which i need to convert it to a normal byte[]
how to do this ?
Asked
Active
Viewed 2.2e+01k times
131

Ofir Hadad
- 1,800
- 3
- 26
- 47

Sudantha
- 15,684
- 43
- 105
- 161
-
What is a "Base64 `byte[]`"? What encoding is it in? – SLaks Jul 18 '11 at 13:46
-
2can you put the code here? – fbarikzehy Jul 15 '15 at 15:59
-
2Yeah, I don't think you have a Base64 `byte[]`. If it's in Base64 format, it's a string. – vapcguy Apr 10 '18 at 21:19
-
I think he meant that he has a byte array Base64 encoded. – KWallace Jul 30 '21 at 18:46
5 Answers
229
You have to use Convert.FromBase64String to turn a Base64 encoded string
into a byte[]
.
-
4
-
6Base64 is always ascii text. So just do `Encoding.ASCII.GetString(base64arr)` first. – Nyerguds Jun 21 '17 at 08:06
-
4
56
This may be helpful
byte[] bytes = System.Convert.FromBase64String(stringInBase64);

Selim Reza
- 1,004
- 9
- 12
9
Try
byte[] incomingByteArray = receive...; // This is your Base64-encoded bute[]
byte[] decodedByteArray =Convert.FromBase64String (Encoding.ASCII.GetString (incomingByteArray));
// This work because all Base64-encoding is done with pure ASCII characters
4
You're looking for the FromBase64Transform
class, used with the CryptoStream
class.
If you have a string, you can also call Convert.FromBase64String
.

SLaks
- 868,454
- 176
- 1,908
- 1,964
3
I've written an extension method for this purpose:
public static byte[] FromBase64Bytes(this byte[] base64Bytes)
{
string base64String = Encoding.UTF8.GetString(base64Bytes, 0, base64Bytes.Length);
return Convert.FromBase64String(base64String);
}
Call it like this:
byte[] base64Bytes = .......
byte[] regularBytes = base64Bytes.FromBase64Bytes();
I hope it helps someone.

Duco
- 246
- 1
- 10