public PropertyEncrypterInfo(PropertyInfo prop, ValueEncrypters encrypters, EncryptDirection direction) : base(prop) { Encrypters = encrypters; Direction = direction; }
/// <summary> /// Decrypts bytes to strings. Null/empty checks should be handled BEFORE this function. /// </summary> /// <param name="v">The encrypted byte array.</param> /// <param name="e">The encryptor.</param> /// <param name="d">The encryption direction.</param> /// <returns>The decrypted string.</returns> protected static string DecryptToString(byte[] v, IByteEncrypter e, EncryptDirection d) { if (d.HasFlag(EncryptDirection.Decrypt)) { return(UTF8.GetString(e.Decrypt(v))); } return(UTF8.GetString(v)); }
/// <summary> /// Encrypts strings. Null/empty checks should be handled BEFORE this function. /// </summary> /// <param name="v">The decrypted string.</param> /// <param name="e">The encryptor.</param> /// <param name="d">The encryption direction.</param> /// <returns>The encrypted base64 string.</returns> protected static string EncryptString(string v, IByteEncrypter e, EncryptDirection d) { if (d.HasFlag(EncryptDirection.Encrypt)) { return(Convert.ToBase64String(e.Encrypt(UTF8.GetBytes(v)))); } return(v); }
/// <summary> /// Decrypts strings. Null/empty checks should be handled BEFORE this function. /// </summary> /// <param name="v">The encrypted base64 string.</param> /// <param name="e">The encryptor.</param> /// <param name="d">The encryption direction.</param> /// <returns>The decrypted string.</returns> protected static string DecryptString(string v, IByteEncrypter e, EncryptDirection d) { if (d.HasFlag(EncryptDirection.Decrypt)) { return(UTF8.GetString(e.Decrypt(Convert.FromBase64String(v)))); } return(v); }
/// <summary> /// Encrypts strings to bytes. Null/empty checks should be handled BEFORE this function. /// </summary> /// <param name="v">The decrypted string.</param> /// <param name="e">The encryptor.</param> /// <param name="d">The encryption direction.</param> /// <returns>The encrypted bytes.</returns> protected static byte[] EncryptFromString(string v, IByteEncrypter e, EncryptDirection d) { if (d.HasFlag(EncryptDirection.Encrypt)) { return(e.Encrypt(UTF8.GetBytes(v))); } return(UTF8.GetBytes(v)); }
private static byte[] Encrypt(DateTime?v, IByteEncrypter e, EncryptDirection d) { if (v.HasValue) { return(null); } return(EncryptBytes(BitConverter.GetBytes(v.Value.ToBinary()), e, d)); }
private static DateTime?Decrypt(byte[] v, IByteEncrypter e, EncryptDirection d) { if (v == null || v.Length == 0) { return(null); } return(DateTime.FromBinary(Convert.ToInt64(DecryptBytes(v, e, d)))); }
private static TimeZoneInfo Decrypt(byte[] v, IByteEncrypter e, EncryptDirection d) { if (v == null || v.Length == 0) { return(null); } return(TimeZoneInfo.FromSerializedString(DecryptToString(v, e, d))); }
private static StringSet Decrypt(string v, IByteEncrypter e, EncryptDirection d) { if (v == null || v.Length == 0) { return(new StringSet()); } return(new StringSet(DecryptString(v, e, d))); }
private static byte[] Encrypt(TimeZoneInfo v, IByteEncrypter e, EncryptDirection d) { if (v == null) { return(null); } return(EncryptFromString(v.ToSerializedString(), e, d)); }
private static TimeSpan?Decrypt(byte[] v, IByteEncrypter e, EncryptDirection d) { if (v == null || v.Length == 0) { return(null); } return(TimeSpan.FromTicks(Convert.ToInt64(DecryptBytes(v, e, d)))); }
private static byte[] Encrypt(TimeSpan?v, IByteEncrypter e, EncryptDirection d) { if (v.HasValue) { return(null); } return(EncryptBytes(BitConverter.GetBytes(v.Value.Ticks), e, d)); }
/// <summary> /// Decrypts bytes. Null/empty checks should be handled BEFORE this function. /// </summary> /// <param name="v">The encrypted byte array.</param> /// <param name="e">The encryptor.</param> /// <param name="d">The encryption direction.</param> /// <returns>The decrypted bytes.</returns> protected static byte[] DecryptBytes(byte[] v, IByteEncrypter e, EncryptDirection d) { if (d.HasFlag(EncryptDirection.Decrypt)) { return(e.Decrypt(v)); } return(v); }
private static byte[] Encrypt(TimeSpan v, IByteEncrypter e, EncryptDirection d) { if (v == TimeSpan.Zero) { return(null); } return(EncryptBytes(BitConverter.GetBytes(v.Ticks), e, d)); }
private static string Decrypt(byte[] v, IByteEncrypter e, EncryptDirection d) { if (v == null) { return(null); } if (v.Length == 0) { return(string.Empty); } return(DecryptToString(v, e, d)); }
private static byte[] Encrypt(string v, IByteEncrypter e, EncryptDirection d) { if (v == null) { return(null); } if (v.Length == 0) { return(new byte[0]); } return(EncryptFromString(v, e, d)); }
private static byte[] Decrypt(byte[] v, IByteEncrypter e, EncryptDirection d) { if (v == null) { return(null); } if (v.Length == 0) { return(new byte[0]); } return(DecryptBytes(v, e, d)); }
private static string Encrypt(StringSet v, IByteEncrypter e, EncryptDirection d) { if (v?.Text == null) { return(null); } if (v.Text.Length == 0) { return(string.Empty); } return(EncryptString(v.Text, e, d)); }
/// <summary> /// Constructs the <see cref="EncryptedAttribute"/> with the optional directional encryption and /// customized encrypter type. /// </summary> /// <param name="direction">The encryption direction to use. (For changes during migration)</param> public EncryptedAttribute(Type converterType, EncryptDirection direction = EncryptDirection.Both) : base(converterType) { if (converterType == null) { throw new ArgumentNullException(nameof(converterType)); } if (typeof(IValueEncrypter).IsAssignableFrom(converterType)) { throw new ArgumentException($"Converter type {converterType.Name} is not a ValueEncrypter!"); } Direction = direction; }
public StringSetValueEncrypter(IByteEncrypter e, EncryptDirection d) : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d)) { }
public TimeZoneInfoValueEncrypter(IByteEncrypter e, EncryptDirection d) : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d)) { }
public DateTimeValueEncrypter(IByteEncrypter e, EncryptDirection d) : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d)) { }
/// <summary> /// Gets the encrypter for the specified encrypt direction. /// </summary> /// <param name="direction">The direction to get the encrypter for.</param> public ValueConverter this[EncryptDirection direction] { get => encrypterDirections[(int)direction];
/// <summary> /// Constructs the <see cref="EncryptedAttribute"/> with the optional directional encryption. /// Uses the default encrypter for this type. /// </summary> /// <param name="direction">The encryption direction to use. (For changes during migration)</param> public EncryptedAttribute(EncryptDirection direction = EncryptDirection.Both) { Direction = direction; }
public TimeSpanNullableValueEncrypter(IByteEncrypter e, EncryptDirection d) : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d)) { }
public BinaryValueEncrypter(IByteEncrypter e, EncryptDirection d) : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d)) { }