public void VerifyEncrypedStringLength100() { var myConfiguration = new Dictionary <string, string> { }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(myConfiguration) .Build(); AESCryptoDelegate aesDelegate = new AESCryptoDelegate( new Mock <ILogger <AESCryptoDelegate> >().Object, configuration); string key = Convert.ToBase64String(Encoding.ASCII.GetBytes("0123456789ABCDEFGHIJKLMNOPQRSTUV")); string plainText = "TSm73LxxXt21TOtu6HBHGPOBqHTFKf4VIMxGWoJrCtyHVdcNwSBdh8F86C9Jwjn2aWRdElQyC3PsuRMA2IXxvQ7m9oHHfm5woo5R"; string encryptedStr = aesDelegate.Encrypt(key, plainText); int blockSize = 16; int expectedSize = plainText.Length + (blockSize - (plainText.Length % blockSize)); double expectedEncodedSize = Math.Ceiling(expectedSize / (double)3) * 4; byte[] encryptedBytes = Convert.FromBase64String(encryptedStr); Assert.True(expectedSize == encryptedBytes.Length && expectedEncodedSize >= encryptedStr.Length); }
public void VerifyEncryptionwithIV() { var myConfiguration = new Dictionary <string, string> { }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(myConfiguration) .Build(); AESCryptoDelegate aesDelegate = new AESCryptoDelegate( new Mock <ILogger <AESCryptoDelegate> >().Object, configuration); string key = Convert.ToBase64String(Encoding.ASCII.GetBytes("0123456789ABCDEFGHIJKLMNOPQRSTUV")); string iv = Convert.ToBase64String(Encoding.ASCII.GetBytes("0123456789ABCDEF")); string plainText = "Hello World"; string expectedStr = "ct9piIgrLBasmnfNPLcHRA=="; string encryptedStr = aesDelegate.Encrypt(key, iv, plainText); Assert.True(expectedStr == encryptedStr); int blockSize = 16; int expectedSize = plainText.Length + (blockSize - (plainText.Length % blockSize)); double expectedEncodedSize = Math.Ceiling(expectedSize / (double)3) * 4; byte[] encryptedBytes = Convert.FromBase64String(encryptedStr); Assert.True(expectedSize == encryptedBytes.Length && expectedEncodedSize >= encryptedStr.Length); }
public void VerifyEncryption() { var myConfiguration = new Dictionary <string, string> { }; var configuration = new ConfigurationBuilder() .AddInMemoryCollection(myConfiguration) .Build(); AESCryptoDelegate aesDelegate = new AESCryptoDelegate( new Mock <ILogger <AESCryptoDelegate> >().Object, configuration); string key = Convert.ToBase64String(Encoding.ASCII.GetBytes("0123456789ABCDEFGHIJKLMNOPQRSTUV")); string plainText = "Hello World"; string expectedStr = "m8zvM4eT5e4Wn1cJvbo+WQ=="; string encryptedStr = aesDelegate.Encrypt(key, plainText); Assert.True(expectedStr == encryptedStr); }