コード例 #1
0
        /// <summary>
        /// Wraps a symmetric key using the specified wrapping key and algorithm.
        /// </summary>
        /// <param name="wrappingKey">The wrapping key</param>
        /// <param name="key">The key to wrap</param>
        /// <param name="algorithm">The algorithm to use</param>
        /// <returns>The wrapped key</returns>
        public static async Task <KeyOperationResult> WrapKeyAsync(this KeyVaultClient client, JsonWebKey wrappingKey, byte[] key, string algorithm)
        {
            KeyOperationResult result = null;

            if (wrappingKey == null)
            {
                throw new ArgumentNullException("wrappingKey");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            return(await client.WrapKeyAsync(wrappingKey.Kid, algorithm, key).ConfigureAwait(false));
        }
コード例 #2
0
        /// <summary>
        /// Encrypts a single block of data. The amount of data that may be encrypted is determined
        /// by the target key type and the encryption algorithm, e.g. RSA, RSA_OAEP
        /// </summary>
        /// <param name="key">The web key to use for encryption</param>
        /// <param name="algorithm">The encryption algorithm</param>
        /// <param name="plaintext">The plain text to encrypt</param>
        /// <returns></returns>
        public static async Task <KeyOperationResult> EncryptDataAsync(this KeyVaultClient client, JsonWebKey key, string algorithm, byte[] plaintext)
        {
            KeyOperationResult result = null;

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (string.IsNullOrEmpty(algorithm))
            {
                throw new ArgumentNullException("algorithm");
            }

            if (plaintext == null)
            {
                throw new ArgumentNullException("plaintext");
            }

            return(await client.EncryptAsync(key.Kid, algorithm, plaintext).ConfigureAwait(false));
        }