public async Task <byte[]> Unwrap(KeyVaultAlgorithm algorithm, byte[] wrappedKey)
 {
     if (!algorithm.CanCryptOrWrap())
     {
         throw new InvalidOperationException("Cannot unwrap with this algorithm type.");
     }
     return((await Client.UnwrapKeyAsync(Identifier.Identifier, algorithm.GetConfigurationString(), wrappedKey)).Result);
 }
 public async Task <byte[]> Encrypt(KeyVaultAlgorithm algorithm, byte[] plainText)
 {
     if (!algorithm.CanCryptOrWrap())
     {
         throw new InvalidOperationException("Cannot encrypt with this algorithm type.");
     }
     return((await Client.EncryptAsync(Identifier.Identifier, algorithm.GetConfigurationString(), plainText)).Result);
 }
 public async Task <bool> Verify(KeyVaultAlgorithm algorithm, byte[] digest, byte[] signature)
 {
     if (!algorithm.CanSignOrVerify())
     {
         throw new InvalidOperationException("Cannot verify with this algorithm type.");
     }
     return(await Client.VerifyAsync(Identifier.Identifier, algorithm.GetConfigurationString(), digest, signature));
 }
 public async Task <byte[]> Sign(KeyVaultAlgorithm algorithm, byte[] digest)
 {
     if (!algorithm.CanSignOrVerify())
     {
         throw new InvalidOperationException("Cannot sign with this algorithm type.");
     }
     return((await Client.SignAsync(Identifier.Identifier, algorithm.GetConfigurationString(), digest)).Result);
 }
        public async Task <string> Wrap(IKeyVaultKey key, KeyVaultAlgorithm algorithm, string valueToWrap)
        {
            var uri     = new Uri(_root, $"keys/{key.Name}/wrapkey?api-version={Version}");
            var command = new
            {
                alg   = algorithm.GetConfigurationString(),
                value = valueToWrap
            };
            var data = await Post(uri, JsonConvert.SerializeObject(command), "application/json");

            return(data.value);
        }
        public async Task <string> Unwrap(IKeyVaultKey key, KeyVaultAlgorithm algorithm, string valueToUnwrap)
        {
            var uri     = new Uri(_root, $"keys/{key.Name}/unwrapkey?api-version={Version}");
            var command = new
            {
                alg   = algorithm.GetConfigurationString(),
                value = valueToUnwrap
            };
            var data = await Post(uri, JsonConvert.SerializeObject(command), "application/json");

            var base64EncodedData = (string)((dynamic)data).value;

            return(base64EncodedData.PadRight(base64EncodedData.Length + (4 - base64EncodedData.Length % 4) % 4, '='));
        }