public void EncryptAndSignUsingPfxTest() { var rsa = new Asymmetric(Path.Join(path, @"Data\certificate.pfx"), password); // EXAMPLE WITH STRING var signature = rsa.Sign(message); Assert.IsTrue(rsa.Verify(message, signature)); var cipher = rsa.Encrypt(message); Assert.AreEqual(message, rsa.Decrypt(cipher)); // CONDENSED EXAMPLE WITH BYTES Assert.IsTrue(rsa.Verify(message, rsa.Sign(message))); Assert.AreEqual(message, rsa.Decrypt(rsa.Encrypt(message))); }
public void Encrypt_Decrypt_Equal() { var sut = new Asymmetric(); var encryptedBytes = sut.Encrypt(PlainText); var decryptedText = sut.Decrypt(encryptedBytes); Assert.AreEqual(PlainText, decryptedText); }
public void BasicCanDecryptTest() { const string PLAINTEXT = "This is a test of the SmartEncryption system..."; var senderKeys = Asymmetric.GenerateKeyPair(); var recipKeys = Asymmetric.GenerateKeyPair(); var cipher = Asymmetric.Encrypt(Encoding.UTF8.GetBytes(PLAINTEXT), senderKeys.PrivateKey, recipKeys.PublicKey); var plain = Asymmetric.Decrypt(cipher, recipKeys.PrivateKey, senderKeys.PublicKey); Assert.AreEqual(PLAINTEXT, Encoding.UTF8.GetString(plain)); }
public void Encrypt_No_Public_Key_Exception() { try { var sut = new Asymmetric(privateKey: PrivateKey); sut.Encrypt(PlainText); } catch (Exception ex) { Assert.AreEqual("PublicKey missing.", ex.Message); throw; } }
public void Encrypt_Decrypt_Existing_Key_Pair_Equal() { var encryptor = new Asymmetric(PublicKey); var decryptor = new Asymmetric(privateKey: PrivateKey); Assert.IsNull(encryptor.PrivateKey); Assert.IsNull(decryptor.PublicKey); var encryptedBytes = encryptor.Encrypt(PlainText); var decryptedText = decryptor.Decrypt(encryptedBytes); Assert.AreEqual(PlainText, decryptedText); }
public IActionResult Encrypt(string plaintext) { string publicKey = _configuration["Asymmetric:PublicKey"]; Asymmetric a = new Asymmetric(); byte[] encryptedBytes = a.Encrypt(plaintext, publicKey); ViewBag.Plaintext = plaintext; ViewBag.EncryptedBytes = Encoding.UTF8.GetString(encryptedBytes); ViewBag.Ciphertext = Convert.ToBase64String(encryptedBytes); return(View()); }