public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool?importToHsm) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } if (webKey == null) { throw new ArgumentNullException("webKey"); } if (webKey.Kty == JsonWebKeyType.RsaHsm && (importToHsm.HasValue && !importToHsm.Value)) { throw new ArgumentException(KeyVaultProperties.Resources.ImportByokAsSoftkeyError); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); webKey.KeyOps = keyAttributes.KeyOps; var keyBundle = new Azure.KeyVault.KeyBundle() { Attributes = (Azure.KeyVault.KeyAttributes)keyAttributes, Key = webKey, Tags = keyAttributes.TagsDirectionary }; try { keyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, keyBundle, importToHsm).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new KeyBundle(keyBundle, this.vaultUriHelper)); }
internal KeyBundle(Azure.KeyVault.KeyBundle keyBundle, VaultUriHelper vaultUriHelper) { if (keyBundle == null) { throw new ArgumentNullException("keyBundle"); } if (keyBundle.Key == null || keyBundle.Attributes == null) { throw new ArgumentException(KeyVaultProperties.Resources.InvalidKeyBundle); } SetObjectIdentifier(vaultUriHelper, keyBundle.KeyIdentifier); Key = keyBundle.Key; Attributes = new KeyAttributes( keyBundle.Attributes.Enabled, keyBundle.Attributes.Expires, keyBundle.Attributes.NotBefore, keyBundle.Key.Kty, keyBundle.Key.KeyOps, keyBundle.Attributes.Created, keyBundle.Attributes.Updated, keyBundle.Tags); }
public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool? importToHsm) { if (string.IsNullOrEmpty(vaultName)) throw new ArgumentNullException("vaultName"); if (string.IsNullOrEmpty(keyName)) throw new ArgumentNullException("keyName"); if (keyAttributes == null) throw new ArgumentNullException("keyAttributes"); if (webKey == null) throw new ArgumentNullException("webKey"); if (webKey.Kty == JsonWebKeyType.RsaHsm && (importToHsm.HasValue && !importToHsm.Value)) throw new ArgumentException(KeyVaultProperties.Resources.ImportByokAsSoftkeyError); string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); webKey.KeyOps = keyAttributes.KeyOps; var keyBundle = new Azure.KeyVault.KeyBundle() { Attributes = (Azure.KeyVault.KeyAttributes)keyAttributes, Key = webKey, Tags = keyAttributes.TagsDirectionary }; try { keyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, keyBundle, importToHsm).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return new KeyBundle(keyBundle, this.vaultUriHelper); }