public void encryptUsingPublicKeyAndDecryptUsingPrivateKey() { Encryption encryption = new Encryption(); byte[] encryptedText = encryption.encrypt(TEXT, asymmetricCryptography.getPublicKey()); string dectyptedText = encryption.decryption(encryptedText, asymmetricCryptography.getPrivateKey()); Assert.AreEqual(TEXT, dectyptedText); }
public void encryptUsingPublicKeyAndDoesNotDecryptUsingDifferentPrivateKey() { RSAAsymmetricCryptography asymmetricCryptographyOther = new RSAAsymmetricCryptography(""); Encryption encryption = new Encryption(); byte[] encryptedText = encryption.encrypt(TEXT, asymmetricCryptography.getPublicKey()); var ex = Assert.Throws <Exception>(() => encryption.decryption(encryptedText, asymmetricCryptographyOther.getPrivateKey())); Assert.That(ex.Message, Is.EqualTo("Private key wrong")); }
public override string action() { name = getCommandInformation(commandDistributeds[1]); rsa = rSAController.getKey(name); if (rsa == null) { return(THE_KEY_DOES_NOT_EXIST + name); } else { return("\n Key private: " + rsa.getPrivateKey()); } }
private string keyAlreadyExists() { name = getCommandInformation(commandDistributeds[2]); if (messageController.getMessage(name) != null) { string text = encryption.decryption(messageController.getMessage(name).text, rsa.getPrivateKey()); return("\n Message Decryption: " + name + ": " + text); } else { return("\nThe message does not exist: " + name); } }