public void GivenEncryptedData_WhenDecryptingData_ThenDecryptsData() { var expectedMessage = "hello world"; var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage); RSAEncryption rsaEncryption = RSAEncryption.CreateContainer("SomeContainer"); var encryptedMessageBytes = rsaEncryption.EncryptData(expectedMessageBytes); var actualMessage = Encoding.UTF8.GetString(rsaEncryption.DecryptData(encryptedMessageBytes)); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); }
public void GivenImportedKey_WhenEncryptingData_ThenEncryptsData_WithImportedKey() { var expectedMessage = "hello world"; var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage); RSAEncryption originalRSAEncryption = RSAEncryption.CreateContainer("SomeContainer"); var exportedPublicKey = originalRSAEncryption.ExportKey(false); var rsaEncryptionWithImportedKey = RSAEncryption.CreateWithKey(exportedPublicKey); var encryptedMessageBytes = rsaEncryptionWithImportedKey.EncryptData(expectedMessageBytes); var actualMessage = Encoding.UTF8.GetString(originalRSAEncryption.DecryptData(encryptedMessageBytes)); Assert.That(actualMessage, Is.EqualTo(expectedMessage)); }