Tag: azure keyvault

如何使用存储在.NET Core 2中的Azure Key Vault中的PFX证书中的私钥?

我在C#中编写了一个ASP.NET Core 2.0网站并启用了Facebook身份validation,因此它需要HTTPS。 我正在使用原生的Kestrel Web服务器来托管该站点,并且有一个监听器设置为每个MS文档获取PFX证书。 从Key Key召回后,我似乎找不到让Kestrel识别私钥的方法。 我知道它存在,因为我写了两个调试语句,表明它实际存在。 这是我用来检索秘密的function,它正在工作。 public static async Task GetKeyVaultCert() { X509Certificate2 pfx; try { var kvClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken)); var secret = await kvClient .GetSecretAsync(“https://macscampvault.vault.azure.net/secrets/letsencrypt”).ConfigureAwait(false); byte[] bytes; if(secret.ContentType == “application/x-pkcs12”) bytes = Convert.FromBase64String(secret.Value); else { bytes = new byte[0]; Console.WriteLine(“secret is not PFX!!”); throw new ArgumentException(“This is not a […]

从c#中获取来自Azure的keyVault的秘密

我有以下代码,它从KeyVault检索秘密。 var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetToken)); var sec = await kv.GetSecretAsync(ConfigurationManager.AppSettings[“SomeURI”]); secretValue = sec.Value ; GetToken方法: async Task GetToken(string authority, string resource, string scope) { var authContext = new AuthenticationContext(authority); ClientCredential clientCred = new ClientCredential(ConfigurationManager.AppSettings[“ClientId”],ConfigurationManager.AppSettings[“ClientSecret”]); AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred); if (result == null) throw new InvalidOperationException(“Failed to obtain the token”); return result.AccessToken; […]

如何使用用户凭据访问Azure Key Vault?

我正在尝试使用我自己的域加入凭据编写一个简单的应用程序来访问Azure KeyVault。 我不知道它是凭证部分还是我如何访问KeyVault,但我不断得到“无效的URI:无法确定URI的格式”exception。 我可以使用Azure PowerShell cmdlet访问KeyVault,但不能使用C#。 这是我的代码: class Program { const string ClientId = “MY AAD CLIENT ID”; static void Main(string[] args) { Console.WriteLine(“Hello, KeyVault!”); var client = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken)); var secret = client.GetSecretAsync(“vaultName”, “secretName”).Result; // Throws Invalid URI: The format of the URI could not be determined Console.WriteLine(secret.Value); Console.ReadLine(); } private static async […]

Azure密钥保管库:访问被拒绝

我有以下代码从Azure密钥保险库获取密码: public static async Task GetToken(string authority, string resource, string scope) { var authContext = new AuthenticationContext(authority); ClientCredential clientCred = new ClientCredential(…); //app id, app secret AuthenticationResult result = await authContext.AcquireTokenAsync(resource, clientCred); if (result == null) throw new InvalidOperationException(“Failed to obtain the JWT token”); return result.AccessToken; } public static string GetSecret(string secretName) { KeyVaultClient keyVaultClient […]

使用未部署在Azure中的应用程序访问Azure密钥保管库存储密钥

美好的一天! 我在大多数文章中都读到需要在Azure中部署应用程序,以便应用程序能够以编程方式访问存储在Azure Key Vault中的机密。 有没有办法不在Azure中部署应用程序并让它仍然能够访问Azure Key Vault以通过使用客户端ID和客户端密钥或证书来获取秘密? 谢谢!

如何在Azure Key Vault中序列化和反序列化PFX证书?

我有一堆字符串和pfx证书,我想存储在Azure Key保险库中,只允许用户/应用程序获取它们。 将字符串存储为Secret并不难,但是如何以可以检索它的方式序列化证书并在C#中反序列化为X509Certificate2对象? 我试着将它存储为钥匙。 这是Azure powershell代码 $securepfxpwd = ConvertTo-SecureString -String ‘superSecurePassword’ -AsPlainText -Force $key = Add-AzureKeyVaultKey -VaultName ‘UltraVault’ -Name ‘MyCertificate’ -KeyFilePath ‘D:\Certificates\BlaBla.pfx’ -KeyFilePassword $securepfxpwd 但是当我试图用GetKeyAsync方法获取它时,我无法使用它。