public void AES256BitKeyTest() { string plainText = "hello world"; string key = "!@#$%^&*()123456!@#$%^&*()123456"; string encrypted = Encryption.AesEncrypt(plainText, key); string decrypted = Encryption.AesDecrypt(encrypted, key); Assert.NotEqual(plainText, encrypted); Assert.Equal(plainText, decrypted); }
public void AesEncryptStringTests() { const string msg = "all good men must act"; const string password = "******"; var encrypt = Encryption.AesEncrypt(msg, password); var decrypt = Encryption.AesDecrypt(encrypt, password); Assert.Equal(msg, decrypt); }
/// <summary> /// Encrypts the model properties of ISqlDataModel object defined by SQLData instance type dictionary. /// </summary> /// <param name="dict">Dict.</param> /// <param name="obj">Object.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static void EncryptedDataModelProperties <T>(this Dictionary <Type, PropertyInfo[]> dict, T obj) where T : new() { var props = dict[typeof(T)]; if (props.Count() > 0) { foreach (var prop in props) { prop.SetValue(obj, Encryption.AesEncrypt(prop.GetString(obj), CoreSettings.Config.AESEncryptionKey), null); } } }
public void AesEncryptStringTests_BadPassword() { const string msg = "all good men must act"; const string password = "******"; var encrypt = Encryption.AesEncrypt(msg, password); Assert.Throws <CryptographicException>(() => Encryption.AesDecrypt(encrypt, "Bad password")); var decrypt = Encryption.AesDecrypt(encrypt, password); Assert.Equal(msg, decrypt); }
public void EncrypTest() { // // TODO: 在此处添加测试逻辑 // string QQ = "2426837192"; string expectedResult = QQ; string cipherText = Encryption.AesEncrypt(QQ); Assert.AreEqual(expectedResult, Encryption.AesDecrypt(cipherText)); }
public void AesEncryptDecryptTests() { var msg = "all good men must act"; var data1 = Encoding.UTF8.GetBytes(msg); var password = "******"; var key = Encryption.KeyFromPassword(password); var edata1 = Encryption.AesEncrypt(data1, key); var ddata1 = Encryption.AesDecrypt(edata1, key); Assert.Equal(data1, ddata1); Assert.Equal(msg, Encoding.UTF8.GetString(ddata1)); }
public void AesEncryptDecryptTest_With_InitializationVector() { var msg = "all good men must act"; var data1 = Encoding.UTF8.GetBytes(msg); var password = "******"; var key = Encryption.KeyFromPassword(password); var iv = Encryption.InitializationVector(key, data1); var edata1 = Encryption.AesEncrypt(data1, key, iv, true); var ddata1 = Encryption.AesDecrypt(edata1, key, iv); Assert.Equal(data1, ddata1); Assert.Equal(msg, Encoding.UTF8.GetString(ddata1)); }
/// <summary> /// Encrypts the model properties of ObservableObject lists. /// </summary> /// <param name="list">List.</param> /// <typeparam name="T">The 1st type parameter.</typeparam> public static void EncryptedModelProperties <T>(IEnumerable <T> list) where T : BindableObject { var props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance) .Where(p => p.GetCustomAttributes(typeof(EncryptedPropertyAttribute)).Count() > 0).ToArray(); if (props.Count() > 0) { foreach (var prop in props) { foreach (var obj in list) { prop.SetValue(obj, Encryption.AesEncrypt(prop.GetString(obj), CoreSettings.Config.AESEncryptionKey), null); } } } }
public void AESThrowsInvalidKeyException() { string plainText = "hello world"; for (int i = 0; i < 100; i++) { string key = RandomString(i); var exception = Record.Exception(() => Encryption.AesEncrypt(plainText, key)); if (i == 16 || i == 24 || i == 32) { Assert.Null(exception); } else { Assert.NotNull(exception); Assert.IsType <System.Security.Cryptography.CryptographicException>(exception); } } }
public void AesEncryptTests() { var msg = "all good men must act"; var data1 = msg.Utf8ToBytes(); var password = "******"; var key = Encryption.KeyFromPassword(password); { var edata1 = Encryption.AesEncrypt(data1, key); var ddata1 = Encryption.AesDecrypt(edata1, key); Assert.Equal(data1, ddata1); Assert.Equal(msg, Encoders.Utf8.Encode(ddata1)); } { var iv = Encryption.InitializationVector(key, data1); var edata1 = Encryption.AesEncrypt(data1, key, iv, true); var ddata1 = Encryption.AesDecrypt(edata1, key, iv); Assert.Equal(data1, ddata1); Assert.Equal(msg, Encoders.Utf8.Encode(ddata1)); } }