pticrix
pticrix
CC#
Created by pticrix on 1/13/2023 in #help
✅ JSON Contract : modifying the value of a property, using System.Text.Json 7
Note that the Encryption class is a custom class, not one from the Framework.
4 replies
CC#
Created by pticrix on 1/13/2023 in #help
✅ JSON Contract : modifying the value of a property, using System.Text.Json 7
[AttributeUsage(AttributeTargets.Property)]
public class JsonEncryptAttribute : Attribute
{
}

public class EncryptedStringPropertyResolver : DefaultJsonTypeInfoResolver
{

private readonly byte[] _encKey;
private readonly byte[] _encIV;

public EncryptedStringPropertyResolver(byte[] encKey, byte[] encIV)
{
_encKey = encKey;
_encIV = encIV;
}


public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
JsonTypeInfo typeInfo = base.GetTypeInfo(type, options);
if (typeInfo.Kind != JsonTypeInfoKind.Object) return typeInfo;

foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.AttributeProvider is { } provider &&
provider.IsDefined(typeof(JsonEncryptAttribute), inherit: true))
{
// serialization
propertyInfo.Get = obj =>
{
PropertyInfo property = typeInfo.Type.GetProperty(propertyInfo.Name); // linking JsonProperty with Property, in order to access the field
return property == null ? null : Encryption.Encrypt(property.GetValue(obj).ToString(), _encKey, _encIV);
};

// deserialization
propertyInfo.Set = (_, val) =>
Encryption.Decrypt(val.ToString(), _encKey, _encIV);

}
}
return typeInfo;
}
}
[AttributeUsage(AttributeTargets.Property)]
public class JsonEncryptAttribute : Attribute
{
}

public class EncryptedStringPropertyResolver : DefaultJsonTypeInfoResolver
{

private readonly byte[] _encKey;
private readonly byte[] _encIV;

public EncryptedStringPropertyResolver(byte[] encKey, byte[] encIV)
{
_encKey = encKey;
_encIV = encIV;
}


public override JsonTypeInfo GetTypeInfo(Type type, JsonSerializerOptions options)
{
JsonTypeInfo typeInfo = base.GetTypeInfo(type, options);
if (typeInfo.Kind != JsonTypeInfoKind.Object) return typeInfo;

foreach (JsonPropertyInfo propertyInfo in typeInfo.Properties)
{
if (propertyInfo.AttributeProvider is { } provider &&
provider.IsDefined(typeof(JsonEncryptAttribute), inherit: true))
{
// serialization
propertyInfo.Get = obj =>
{
PropertyInfo property = typeInfo.Type.GetProperty(propertyInfo.Name); // linking JsonProperty with Property, in order to access the field
return property == null ? null : Encryption.Encrypt(property.GetValue(obj).ToString(), _encKey, _encIV);
};

// deserialization
propertyInfo.Set = (_, val) =>
Encryption.Decrypt(val.ToString(), _encKey, _encIV);

}
}
return typeInfo;
}
}
4 replies
CC#
Created by pticrix on 1/13/2023 in #help
✅ JSON Contract : modifying the value of a property, using System.Text.Json 7
Solved it like a big boy.
4 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
yeah def, I had no log to look at, only one line with no error. Thanks for you help, made me look at things just at the right angles.
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
but it was hidden in a nuget
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
yeah I was looking for that! Even did a search
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
I was stubbornly looking at the kestrel in Program
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
and lo and behold :
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
naming. There were overload of configuration above my screenshot
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
not type
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
your naming thing put me on the right path
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
I found it
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
FUCK
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
fuck
87 replies
CC#
Created by pticrix on 9/28/2022 in #help
System.Net.Sockets spookyness
Ok, I'll take some time to look into that avenue. Thanks!
87 replies