Encodes bytes into websafe base 64
Ejemplo n.º 1
0
 /// <summary>
 /// Writes the JSON representation of the object.
 /// </summary>
 /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param>
 /// <param name="value">The value.</param>
 /// <param name="serializer">The calling serializer.</param>
 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     if (writer is BsonDataWriter)
     {
         serializer.Serialize(writer, value);
     }
     else
     {
         var encoded = WebSafeBase64.Encode(((byte[])value));
         serializer.Serialize(writer, new string(encoded));
         Secure.Clear(encoded);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Reads the JSON representation of the object.
 /// </summary>
 /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
 /// <param name="objectType">Type of the object.</param>
 /// <param name="existingValue">The existing value of object being read.</param>
 /// <param name="serializer">The calling serializer.</param>
 /// <returns>The object value.</returns>
 public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                 JsonSerializer serializer)
 {
     byte[] final;
     if (reader is BsonDataReader || reader is RawJsonReader)
     {
         final = serializer.Deserialize <byte[]>(reader);
     }
     else
     {
         var base64 = (serializer.Deserialize <string>(reader) ?? String.Empty).ToCharArray();
         final = WebSafeBase64.Decode(base64);
         Secure.Clear(base64);
     }
     return(final);
 }