De-serialize Base64 String to Object


/ Published in: C#
Save to your folder(s)

De-serializes a Base64 String back to it's original object. First x characters should indicate the byte length of the encoded data.


Copy this code and paste it in your HTML
  1. public static object DeserializeBase64(string s)
  2. {
  3. // We need to know the exact length of the string - Base64 can sometimes pad us by a byte or two
  4. int p = s.IndexOf(':');
  5. int length = Convert.ToInt32(s.Substring(0, p));
  6.  
  7. // Extract data from the base 64 string!
  8. byte[] memorydata = Convert.FromBase64String(s.Substring(p + 1));
  9. MemoryStream rs = new MemoryStream(memorydata, 0, length);
  10. BinaryFormatter sf = new BinaryFormatter();
  11. object o = sf.Deserialize(rs);
  12. return o;
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.