public static bool SetItemsThrow(string Id, string VaultName, string Name, string Version, string Enabled, Nullable <DateTime> Expires, Nullable <DateTime> NotBefore, string ContentType, string[] Tags, string SecretValue, bool Exact) { KeyVaultHelper.GetItemThrow(null, VaultName, true); bool issuccessful = SetItems(Id, VaultName, Name, Version, Enabled, Expires, NotBefore, ContentType, Tags, SecretValue, Exact); if (!issuccessful) { throw new PSAdminException(PSAdminExceptionType.RowUpdate); } return(true); }
internal static byte[] GetVaultKey(string VaultName) { Data.KeyVault KeyVault = KeyVaultHelper.GetItemThrow(null, VaultName, true); if ( String.IsNullOrEmpty(KeyVault.Thumbprint) ) return KeyVault.VaultKey; Data.KeyVaultCertificate Certificate = KeyVaultCertificateHelper.GetItemThrow(null, VaultName, null, KeyVault.Thumbprint, null, true, true); // Decrypt the Key X509Certificate2 x509 = (X509Certificate2)Certificate.Certificate; if ((x509.HasPrivateKey == false) || (x509.PrivateKey == null)) { throw new InvalidOperationException("Certificate does not contain PrivateKey"); } return ((RSACryptoServiceProvider)x509.PrivateKey).Decrypt(KeyVault.VaultKey, true); }