public void DeriveKey_CreateCommonKeyAndEncryptString_Pass() { ECDiffieHellmanAgreement agreement; byte[] commonKey; byte[] iv; string messageFromBob = "Hello my friend, how are you?"; string encrypted; string decrypted; using(var alice = new ECDiffieHellmanCipher<ECDiffieHellmanCng>()) { agreement = alice.Agreement; using(var bob = new ECDiffieHellmanCipher<ECDiffieHellmanCng>(agreement)) { commonKey = alice.DeriveKey(bob.PublicKey); using (var cipher = new SymmetricCipher<AesManaged>(commonKey, out iv)) encrypted = cipher.EncryptToString(messageFromBob); } using (var cipher = new SymmetricCipher<AesManaged>(commonKey, iv)) decrypted = cipher.DecryptToString(encrypted); } Assert.AreEqual(messageFromBob, decrypted); }
public void EncryptToString_AesEncryptToStringAndDecryptToString_Pass() { string plainText = "Encrypt me but don' forget me."; string encryptedText; string decryptedText; using(var cipher = new SymmetricCipher<AesManaged>("passwd", "mysalt1337")) { encryptedText = cipher.EncryptToString(plainText); decryptedText = cipher.DecryptToString(encryptedText); } Assert.AreEqual(plainText, decryptedText); }
public void AesBasicCipher1_SameInstance_ComparesOutput() { string plainText = "Encrypt me but don' forget me."; byte[] plaindata = Encoding.UTF8.GetBytes(plainText); string encryptedText; string decryptedText; using (var cipher = new SymmetricCipher<AesManaged>("passwd", "mysalt1337")) { encryptedText = cipher.EncryptToString(plaindata); decryptedText = cipher.DecryptToString(encryptedText); } Assert.AreEqual(plainText, decryptedText); }
public void ConstructorWithOutParams_InstantiateNewWithRandomSaltAndIV_Pass() { string passwd = "PassIWantt0youS3"; string message = "This is my cool message, you fokkin w0t m8"; string cipherMessage; string decrypted; byte[] salt; byte[] IV; using (var cipher = new SymmetricCipher<AesManaged>(passwd, out salt, out IV)) { cipherMessage = cipher.EncryptToString(message); } using(var cipher = new SymmetricCipher<AesManaged>(passwd, salt, IV)) { decrypted = cipher.DecryptToString(cipherMessage); } Assert.AreEqual(message, decrypted); }
public void AesBasicCipher4_SameInstance_ComparesOutput() { string plainText = "Encryption is pretty fun"; byte[] plainTextArr = Encoding.UTF8.GetBytes(plainText); string encryptStr; byte[] decryptArr; string decryptStr; using (var cipher = new SymmetricCipher<AesManaged>("mypasswd2", "mysalt1337bb")) { encryptStr = cipher.EncryptToString(plainText); decryptArr = cipher.Decrypt(encryptStr); } decryptStr = Encoding.UTF8.GetString(decryptArr); Assert.AreEqual(plainText, decryptStr); }