You have a string that contains information such as a bitmap encoded as base64. You need to decode this data (which may have been embedded in an email message) from a string into a byte[] so that you can access the original binary.
The Convert class in the FCL provides two static method FromBase64CharArray, and FromBase64String to convert a string/char[] array to binary format. In Convert.FromBase64CharArray, a char[] may be encoded to a byte[] array. If you’re converting a string, you need to use string ToCharArray method to convert the string to char[] array. The snippet code as show below:
private static byte[] Base64DecodeStringChar(string input) { return Convert.FromBase64CharArray(input.ToCharArray(), 0, input.Length); }
In Convert.FromBase64String, thing become simpler. All you need is the string input, the output of the method is byte[] array.
private static byte[] Base64DecodeStringString(string input) { return Convert.FromBase64String(input); }
The sample source code is available to download:Decoding Base64 Encoded Code
Popularity: 1% [?]
RSS feed for comments on this post · TrackBack URI
Leave a reply