Пример #1
0
        public async Task KeyVault_RsaKeyRSA15()
        {
            RsaKey key = GetTestRsaKey();

            // Wrap and Unwrap
            var wrapped = await key.WrapKeyAsync(CEK, Rsa15.AlgorithmName).ConfigureAwait(false);

            var unwrapped = await key.UnwrapKeyAsync(wrapped.Item1, Rsa15.AlgorithmName).ConfigureAwait(false);

            // Assert
            Assert.True(wrapped.Item2.Equals("RSA_15"));
            Assert.True(unwrapped.SequenceEqual(CEK));

            // Encrypt and Decrypt
            var encrypted = await key.EncryptAsync(CEK, null, null, Rsa15.AlgorithmName).ConfigureAwait(false);

            var decrypted = await key.DecryptAsync(encrypted.Item1, null, null, null, Rsa15.AlgorithmName).ConfigureAwait(false);

            // Assert
            Assert.True(encrypted.Item3.Equals("RSA_15"));
            Assert.True(decrypted.SequenceEqual(CEK));
        }
Пример #2
0
        public async Task KeyVault_RsaKeyDefaultAlgorithm()
        {
            RsaKey key = GetTestRsaKey();

            Assert.Equal("RSA-OAEP", key.DefaultEncryptionAlgorithm);
            Assert.Equal("RSA-OAEP", key.DefaultKeyWrapAlgorithm);
            Assert.Equal("RS256", key.DefaultSignatureAlgorithm);

            var wrapped = await key.WrapKeyAsync(CEK, null).ConfigureAwait(false);

            var unwrapped = await key.UnwrapKeyAsync(wrapped.Item1, null).ConfigureAwait(false);

            // Assert
            Assert.Equal("RSA-OAEP", wrapped.Item2);
            Assert.True(unwrapped.SequenceEqual(CEK));

            var encrypted = await key.EncryptAsync(CEK, null, null, null).ConfigureAwait(false);

            var decrypted = await key.DecryptAsync(encrypted.Item1, null, null, null, null).ConfigureAwait(false);

            // Assert
            Assert.Equal("RSA-OAEP", encrypted.Item3);
            Assert.True(decrypted.SequenceEqual(CEK));
        }