public void RsaCipherCipher_Encryption_Test() { var rsaKey = RsaCipher.GetKey(); var encrypt = RsaCipher.Encrypt("VeyselMUTLU", rsaKey["PublicKey"]); var decrypt = RsaCipher.Decrypt(encrypt, rsaKey["PrivateKey"]); Assert.AreEqual("VeyselMUTLU", decrypt); }
public void EncryptTest() { RsaKey key = null; // TODO: Initialize to an appropriate value RsaCipher target = new RsaCipher(key); // TODO: Initialize to an appropriate value byte[] data = null; // TODO: Initialize to an appropriate value byte[] expected = null; // TODO: Initialize to an appropriate value byte[] actual; actual = target.Encrypt(data); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
public void EncryptAndDecrypt() { var pair = new RsaKeyPair(); var str = "Hello"; var encoded = RsaCipher.Encrypt(str, pair.PublicKey); Assert.NotEqual(str, encoded); var decoded = RsaCipher.Decrypt(encoded, pair.PrivateKey); Assert.Equal(str, decoded); }
public EncryptedMessage Encrypt(string messageText, int recieverId) { if (messageText == null) { throw new ArgumentException("Message text cannot be null"); } IContactModel receiverContact = _storageService.GetContacts().FirstOrDefault(c => c.Id == recieverId); if (receiverContact == null) { throw new ArgumentException("Contact with id of receiverId does not exist"); } EncryptedMessage encMsg = new EncryptedMessage(); AesCipher aes = new AesCipher(); // set initiazlization vector encMsg.Iv = FormatConverter.BytesToString64(aes.IV); // enccrypt message text symmetrically byte[] messageBytes = FormatConverter.StringToBytes(messageText); byte[] encryptedMessageBytes = aes.Encrypt(messageBytes); encMsg.Body = FormatConverter.BytesToString64(encryptedMessageBytes); // encrypt symmetric key with receivers public key string receiverPublicKey = receiverContact.PublicKey; RsaCipher rsa = new RsaCipher(receiverPublicKey); byte[] encryptedSymmetricKeyBytes = rsa.Encrypt(aes.Key); encMsg.SymmetricKey = FormatConverter.BytesToString64(encryptedSymmetricKeyBytes); // create digital signature of message text (using senders private key) string senderKeyPair = _storageService.GetUser().KeyPair; rsa = new RsaCipher(senderKeyPair); byte[] digitalSignatureBytes = rsa.CreateDigitalSignature(messageBytes); encMsg.DigitalSignature = FormatConverter.BytesToString64(digitalSignatureBytes); return(encMsg); }