public void RoundTrip_Ok() { // Depends on client being configured in app.config or ambient environment. IAmazonKeyManagementService client = AWSClientFactory.CreateAmazonKeyManagementServiceClient(); string keyid = ConfigurationManager.AppSettings["kmsKeyId"]; ICryptoProvider crypto = new EnvelopeCryptoProvider(client, keyid); const string plaintext = "Peek-a-boo!"; string dataKey; string ciphertext = crypto.Encrypt(out dataKey, plaintext); dataKey.Should().NotBeEmpty(); ciphertext.Should().NotBe(plaintext); string decrypted = crypto.Decrypt(dataKey, ciphertext); decrypted.Should().Be("Peek-a-boo!"); }
public void SetUp() { RealKey = GenerateKey(); DummyDataKeyProvider = new DummyDataKeyProvider { GeneratedKey = RealKey, GeneratedEncryptedKey = Bytes(200, 201, 202) }; // These contexts will be used to verify that using a different context produces different ciphertext. Context1 = new Dictionary <string, string> { { "id", "1" } }; Context2 = new Dictionary <string, string> { { "id", "2" } }; // Set up the dummy key provider to return an easily testable encrypted key based on the crypto context. DummyDataKeyProvider.EncryptedKeyById["1"] = Bytes(1, 1, 1); DummyDataKeyProvider.EncryptedKeyById["2"] = Bytes(2, 2, 2); Provider = new EnvelopeCryptoProvider(DummyDataKeyProvider); }