public void GivenValidData_WhenExportingKey_ThenReturnsExportedKeyToXML() { RSAEncryption encryption = RSAEncryption.CreateContainer("SomeContainer"); var rsaExport = encryption.ExportKey(false); Assert.That(rsaExport, Is.Not.Null); }
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)); }
public void GivenContainerAlreadyExists_WhenLoadingContainerWithSameName_ThenLoadsContainer() { RSAEncryption.CreateContainer("Container"); Assert.DoesNotThrow(() => RSAEncryption.LoadContainer("Container")); }
public void GivenContainerAlreadyExistsForCurrentUser_WhenCreatingContainerWithSameName_ThenLoadsContainer() { RSAEncryption.CreateSecureContainer("Container", User); Assert.DoesNotThrow(() => RSAEncryption.CreateContainer("Container")); }
public void GivenContainerAlreadyExistsForAnotherUser_WhenCreatingContainerWithSameName_ThenThrowsCryptographicException() { RSAEncryption.CreateSecureContainer("Container", "SYSTEM"); Assert.Throws <CryptographicException>(() => RSAEncryption.CreateContainer("Container")); }