コード例 #1
0
 public PropertyEncrypterInfo(PropertyInfo prop, ValueEncrypters encrypters,
                              EncryptDirection direction)
     : base(prop)
 {
     Encrypters = encrypters;
     Direction  = direction;
 }
コード例 #2
0
 /// <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));
 }
コード例 #3
0
 /// <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);
 }
コード例 #4
0
 /// <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);
 }
コード例 #5
0
 /// <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));
 }
コード例 #6
0
 private static byte[] Encrypt(DateTime?v, IByteEncrypter e, EncryptDirection d)
 {
     if (v.HasValue)
     {
         return(null);
     }
     return(EncryptBytes(BitConverter.GetBytes(v.Value.ToBinary()), e, d));
 }
コード例 #7
0
 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))));
 }
コード例 #8
0
 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)));
 }
コード例 #9
0
 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)));
 }
コード例 #10
0
 private static byte[] Encrypt(TimeZoneInfo v, IByteEncrypter e, EncryptDirection d)
 {
     if (v == null)
     {
         return(null);
     }
     return(EncryptFromString(v.ToSerializedString(), e, d));
 }
コード例 #11
0
 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))));
 }
コード例 #12
0
 private static byte[] Encrypt(TimeSpan?v, IByteEncrypter e, EncryptDirection d)
 {
     if (v.HasValue)
     {
         return(null);
     }
     return(EncryptBytes(BitConverter.GetBytes(v.Value.Ticks), e, d));
 }
コード例 #13
0
 /// <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);
 }
コード例 #14
0
 private static byte[] Encrypt(TimeSpan v, IByteEncrypter e, EncryptDirection d)
 {
     if (v == TimeSpan.Zero)
     {
         return(null);
     }
     return(EncryptBytes(BitConverter.GetBytes(v.Ticks), e, d));
 }
コード例 #15
0
 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));
 }
コード例 #16
0
 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));
 }
コード例 #17
0
 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));
 }
コード例 #18
0
 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));
 }
コード例 #19
0
 /// <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;
 }
コード例 #20
0
 public StringSetValueEncrypter(IByteEncrypter e, EncryptDirection d)
     : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d))
 {
 }
コード例 #21
0
 public TimeZoneInfoValueEncrypter(IByteEncrypter e, EncryptDirection d)
     : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d))
 {
 }
コード例 #22
0
 public DateTimeValueEncrypter(IByteEncrypter e, EncryptDirection d)
     : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d))
 {
 }
コード例 #23
0
 /// <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];
コード例 #24
0
 /// <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;
 }
コード例 #25
0
 public TimeSpanNullableValueEncrypter(IByteEncrypter e, EncryptDirection d)
     : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d))
 {
 }
コード例 #26
0
 public BinaryValueEncrypter(IByteEncrypter e, EncryptDirection d)
     : base(v => Encrypt(v, e, d), v => Decrypt(v, e, d))
 {
 }