반응형
C# Convert a Base64 -> byte[]
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 ?
You have to use Convert.FromBase64String to turn a Base64 encoded string
into a byte[]
.
This may be helpful
byte[] bytes = System.Convert.FromBase64String(stringInBase64);
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
You're looking for the FromBase64Transform
class, used with the CryptoStream
class.
If you have a string, you can also call Convert.FromBase64String
.
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.
참고URL : https://stackoverflow.com/questions/6733845/c-sharp-convert-a-base64-byte
반응형
'Nice programing' 카테고리의 다른 글
fetch vs. [] when working with hashes? (0) | 2020.11.16 |
---|---|
Why does Java let you cast to a collection? (0) | 2020.11.16 |
How to find index position of an element in a list when contains returns true (0) | 2020.11.16 |
Matplotlib에서 3D 큐브, 구 및 벡터 플로팅 (0) | 2020.11.16 |
Pass data through segue (0) | 2020.11.16 |