/// <summary> /// Decrypts the <paramref name="encrypted"/> data with the <paramref name="cipher"/>. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="cipher">The cipher.</param> /// <param name="encrypted">The encrypted.</param> /// <returns>T.</returns> public static Nullable <T> DecryptNullable <T>( this ICipher cipher, byte[] encrypted) where T : struct { if (cipher == null) { throw new ArgumentNullException(nameof(cipher)); } if (encrypted == null) { throw new ArgumentNullException(nameof(encrypted)); } if (encrypted.Length < 2) { throw new ArgumentException(Resources.InvalidArgumentLength, nameof(encrypted)); } if (!EncryptTypedData.ContainsKey(typeof(T))) { throw new ArgumentException("The specified data type cannot be decrypted."); } var decrypted = cipher.Decrypt(encrypted); if (decrypted.Length < 2) { throw new ArgumentException("The argument is not a valid encrypted Nullable<T> value."); } return(FromByteArray.ToNullable <T>(decrypted)); }