public void TestAes() { var aes = new AesEncryptionProvider(); var key = aes.Key; var aes2 = new AesEncryptionProvider(); var message = "Unit Testing With Xunit is cool!!"; var sb = new StringBuilder(message); for (int i = 0; i < 1000; i++) { sb.Append(i.ToString()); sb.Append(" : "); sb.Append(message); sb.AppendLine(); } var Message = sb.ToString(); var Enc1 = aes.Encrypt(message); var Enc2 = aes.Encrypt(Message); var Enc3 = aes2.Encrypt(Message); var Enc4 = aes.Encrypt(Message); Assert.NotEqual(Enc1, Enc2); Assert.NotEqual(Enc2, Enc3); Assert.Equal(Enc2, Enc4); Assert.Equal(message, aes.Decrpty(Enc1)); Assert.Equal(Message, aes.Decrpty(Enc2)); Assert.NotEqual(Message, aes.Decrpty(Enc1)); Assert.Equal(Message, aes2.Decrpty(Enc3)); }
public void Should_return_cypher_text_when_encrypting() { var inputText = "this is some text"; var result = provider.Encrypt(inputText); result.ShouldNotEqual(inputText); }
public void Encrypt_StaticEncryptIVPrependedInReturn() { byte[] key = Convert.FromBase64String("ho8LEsB+9jB9ByG9eFEDHr1r6UQjdgOG"); byte[] iv = Convert.FromBase64String("TQ36HLyQYwO0bYf5YFXMSw=="); var result = AesEncryptionProvider.Encrypt("secret value", key, iv); byte[] ivFromResult = Convert.FromBase64String(result)[..16];
public void TestEncryptionAndDecryption() { var key = AesEncryptionProvider.InitializeEncryptionKey(); var encrypted = AesEncryptionProvider.Encrypt(key, Data); var decrypted = AesEncryptionProvider.Decrypt(key, encrypted); Assert.AreEqual(Data, decrypted); }
public void AesEncryptionProvider_Encrypt_Decrypt_PlainText() { // arrange const string expected = "This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text. This is some plain text."; var aes = new AesEncryptionProvider(new TestCryptoKeyProvider("9781908006028", new Guid("F588C946-386F-4A49-A333-64A189D07DD4"))); // act var encrypted = aes.Encrypt(Encoding.UTF8.GetBytes(expected)); var decrypted = aes.Decrypt(encrypted); var actual = Encoding.ASCII.GetString(decrypted); // assert Assert.AreEqual(actual, expected); }
public void Encrypt_StaticEncryptValuesSuccess(string value, string keyB64, string ivB64, string expectedB64) { // arrange var key = Convert.FromBase64String(keyB64); var iv = Convert.FromBase64String(ivB64); var asBytes = Convert.FromBase64String(expectedB64); var expectedBytes = new byte[iv.Length + asBytes.Length]; Array.ConstrainedCopy(iv, 0, expectedBytes, 0, iv.Length); Array.ConstrainedCopy(asBytes, 0, expectedBytes, iv.Length, asBytes.Length); var expected = Convert.ToBase64String(expectedBytes); // act var actual = AesEncryptionProvider.Encrypt(value, key, iv); // assert Assert.Equal(expected, actual); Assert.True(actual.Length > 16); Assert.True(IsBase64String(actual)); }
public void EncryptionTests() { var key = AesEncryptionProvider.GenerateKey(); Assert.IsNotNull(key); Assert.IsTrue(key.Length > 0); var aes = new AesEncryptionProvider(key); const string toEncrypt = "A man, a plan, a canal. Panama."; var encrypted = aes.Encrypt(toEncrypt); Assert.IsNotNull(encrypted); Assert.IsTrue(encrypted.Length > 0); Assert.AreNotEqual(toEncrypt, encrypted); var decrypted = aes.Decrypt(encrypted); Assert.IsNotNull(decrypted); Assert.IsTrue(decrypted.Length > 0); Assert.AreEqual(toEncrypt, decrypted); }
public IAsyncOperation <Guid> AddAccountToRoamingStorageAsync(Account account, Guid roamingGuid) { return(Task.Run(async() => { if (!_isInitialized) { await InitializeStorageAsync(); } if (IsRoamingStorageEncrypted && String.IsNullOrEmpty(LocalEncryptionTransferKey)) { throw new InvalidOperationException("The storage is encrypted but no key is provided."); } if (!IsRoamingStorageEncrypted) { throw new SecurityException("NSA is watching you"); } var accountFile = await _accountFolder.CreateFileAsync(roamingGuid + ".blob"); var accountJson = new JsonObject { { "AccountName", JsonValue.CreateStringValue(account.AccountName) }, { "AccountKeyBase32", JsonValue.CreateStringValue(account.AccountKeyBase32) }, { "AccountIcon", JsonValue.CreateStringValue(account.AccountIcon) } }; // Encrypt the data var accountJsonString = accountJson.Stringify(); var accountJsonStringEncrypted = AesEncryptionProvider.Encrypt(LocalEncryptionTransferKey, accountJsonString); var transcation = await accountFile.OpenTransactedWriteAsync(); var streamwriter = new StreamWriter(transcation.Stream.AsStream()); streamwriter.Write(accountJsonStringEncrypted); // Commit data streamwriter.Flush(); await transcation.CommitAsync(); return roamingGuid; }).AsAsyncOperation()); }
public void TestEncryption() { var key = AesEncryptionProvider.InitializeEncryptionKey(); AesEncryptionProvider.Encrypt(key, Data); }