public virtual async Task <Response <UnwrapResult> > UnwrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken = default)
        {
            var parameters = new KeyWrapParameters()
            {
                Algorithm = algorithm.ToString(),
                Key       = encryptedKey
            };

            using DiagnosticScope scope = Pipeline.CreateScope("Azure.Security.KeyVault.Keys.Cryptography.RemoteCryptographyClient.UnwrapKey");
            scope.AddAttribute("key", _keyId);
            scope.Start();

            try
            {
                return(await Pipeline.SendRequestAsync(RequestMethod.Post, parameters, () => new UnwrapResult { Algorithm = algorithm }, cancellationToken, "/unwrapKey").ConfigureAwait(false));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #2
0
        public UnwrapResult UnwrapKey(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken)
        {
            Argument.AssertNotNull(encryptedKey, nameof(encryptedKey));

            RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding();

            byte[] key = Decrypt(encryptedKey, padding);

            UnwrapResult result = null;

            if (key != null)
            {
                result = new UnwrapResult
                {
                    Algorithm = algorithm,
                    Key       = key,
                    KeyId     = _jwk.Id,
                };
            }

            return(result);
        }
        public virtual Response <UnwrapResult> UnwrapKey(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken = default)
        {
            var parameters = new KeyWrapParameters()
            {
                Algorithm = algorithm.ToString(),
                Key       = encryptedKey
            };

            using DiagnosticScope scope = Pipeline.CreateScope($"{nameof(RemoteCryptographyClient)}.{nameof(UnwrapKey)}");
            scope.AddAttribute("key", _keyId);
            scope.Start();

            try
            {
                return(Pipeline.SendRequest(RequestMethod.Post, parameters, () => new UnwrapResult {
                    Algorithm = algorithm
                }, cancellationToken, "/unwrapKey"));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #4
0
        public virtual Response <WrapResult> WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = default)
        {
            var parameters = new KeyWrapParameters()
            {
                Algorithm = algorithm.ToString(),
                Key       = key
            };

            using DiagnosticScope scope = Pipeline.CreateScope("Azure.Security.KeyVault.Keys.Cryptography.RemoteCryptographyClient.WrapKey");
            scope.AddAttribute("key", _keyId);
            scope.Start();

            try
            {
                return(Pipeline.SendRequest(RequestMethod.Post, parameters, () => new WrapResult {
                    Algorithm = algorithm
                }, cancellationToken, "/wrapKey"));
            }
            catch (Exception e)
            {
                scope.Failed(e);
                throw;
            }
        }
예제 #5
0
        public override WrapResult WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken)
        {
            Argument.AssertNotNull(key, nameof(key));

            ThrowIfTimeInvalid();

            RSAEncryptionPadding padding = algorithm.GetRsaEncryptionPadding();

            byte[] encryptedKey = Encrypt(key, padding);

            WrapResult result = null;

            if (encryptedKey != null)
            {
                result = new WrapResult
                {
                    Algorithm    = algorithm,
                    EncryptedKey = encryptedKey,
                    KeyId        = KeyMaterial.Id,
                };
            }

            return(result);
        }
예제 #6
0
        public virtual Task <WrapResult> WrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = default)
        {
            WrapResult result = WrapKey(algorithm, key, cancellationToken);

            return(Task.FromResult(result));
        }
예제 #7
0
 public virtual WrapResult WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = default)
 {
     throw CreateOperationNotSupported(nameof(WrapKey));
 }
예제 #8
0
        public virtual Task <UnwrapResult> UnwrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken = default)
        {
            UnwrapResult result = UnwrapKey(algorithm, encryptedKey, cancellationToken);

            return(Task.FromResult(result));
        }
예제 #9
0
 public virtual WrapResult WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken = default)
 {
     throw new NotSupportedException();
 }
 UnwrapResult ICryptographyProvider.UnwrapKey(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken)
 {
     return(UnwrapKey(algorithm, encryptedKey, cancellationToken));
 }
 async Task <UnwrapResult> ICryptographyProvider.UnwrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] encryptedKey, CancellationToken cancellationToken)
 {
     return(await UnwrapKeyAsync(algorithm, encryptedKey, cancellationToken).ConfigureAwait(false));
 }
 WrapResult ICryptographyProvider.WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken)
 {
     return(WrapKey(algorithm, key, cancellationToken));
 }
예제 #13
0
 WrapResult ICryptographyProvider.WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken)
 {
     return(((RemoteCryptographyClient)this).WrapKey(algorithm, key, cancellationToken));
 }
예제 #14
0
 async Task <WrapResult> ICryptographyProvider.WrapKeyAsync(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken)
 {
     return(await((RemoteCryptographyClient)this).WrapKeyAsync(algorithm, key, cancellationToken).ConfigureAwait(false));
 }
예제 #15
0
 public WrapResult WrapKey(KeyWrapAlgorithm algorithm, byte[] key, CancellationToken cancellationToken)
 {
     // TODO
     throw new NotImplementedException();
 }