add securestringjsonconverter
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SecureString.cs" />
|
||||
<Compile Include="UniquieID.cs" />
|
||||
<Compile Include="SecureStringJsonConverter.cs" />
|
||||
<Compile Include="UniquiIDStringJsonConverter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Cryptography
|
||||
{
|
||||
[JsonConverter(typeof(Json.Converters.SecureStringJsonConverter))]
|
||||
public class SecureString
|
||||
{
|
||||
public static ICrypter DefaultCrypter { get; set; }
|
||||
|
||||
40
Pilz.Cryptography/SecureStringJsonConverter.cs
Normal file
40
Pilz.Cryptography/SecureStringJsonConverter.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json;
|
||||
using Pilz.Cryptography;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Pilz.Json.Converters
|
||||
{
|
||||
public class SecureStringJsonConverter : JsonConverter
|
||||
{
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return typeof(SecureString).IsAssignableFrom(objectType);
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var idString = serializer.Deserialize<string>(reader);
|
||||
SecureString id;
|
||||
|
||||
if (existingValue is object)
|
||||
id = (SecureString)existingValue;
|
||||
else
|
||||
id = new SecureString();
|
||||
|
||||
id.EncryptedValue = idString;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
serializer.Serialize(writer, ((SecureString)value).EncryptedValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user