Azure – Key Vault Certificate
前言
之前有介绍过读写 Certificate Store, 但在 production server 经常会遇到权限的问题.
为了一劳永逸, 可以考虑把 Certificate 放到 Azure Key Vault 里, 然后通过 API 去拿.
这样做的另一个好处是对 Server 依赖更少.
主要参考:
How can I create an X509Certificate2 object from an Azure Key Vault KeyBundle
Azure Key Vault Certificate client library for .NET
Azure Setup
去 Key Vault 页面点击 import

选择 import 添加名字密码就可以了.

Azure CLI
az keyvault certificate import --vault-name "MyProject-KV" --name "oidc-encryption" --file "C:\oidc-encryption.pfx" --password "mypassword"
ASP.NET Core Setup
install nuget
dotnet add package Azure.Identity
dotnet add package Azure.Security.KeyVault.Certificates
dotnet add package Azure.Security.KeyVault.Secrets
get certificate from Azure
var certificateClient = new CertificateClient(new Uri("https://kv-name.vault.azure.net/"), new DefaultAzureCredential());
var secretClient = new SecretClient(new Uri("https://kv-name.vault.azure.net/"), new DefaultAzureCredential());
var certResponse = await certificateClient.GetCertificateAsync("Certificate Name");
var identifier = new KeyVaultSecretIdentifier(certResponse.Value.SecretId);
var secretResponse = await secretClient.GetSecretAsync(identifier.Name, identifier.Version);
var secret = secretResponse.Value;
var privateKeyBytes = Convert.FromBase64String(secret.Value);
var certificate = new X509Certificate2(rawData: privateKeyBytes, password: (string?)null, keyStorageFlags: X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.EphemeralKeySet);
list all certificate
AsyncPageable<CertificateProperties> allCertificates = client.GetPropertiesOfCertificatesAsync();
await foreach (CertificateProperties certificateProperties in allCertificates)
{
Console.WriteLine(certificateProperties.Name);
}
注意它返回的是一个叫 AsyncPageable 的冬冬. 它不是很好操作.
要好的调用体验可以参考: Use System.Linq.Async with AsyncPageable
import certificate to Azure
TODO...
Azure – Key Vault Certificate的更多相关文章
- 【Azure 环境】把OpenSSL生产的自签名证书导入到Azure Key Vault Certificate中报错
问题描述 通过本地生成的自签名证书导入到Azure Key Vault Certificate报错. 错误信息 the specified PEM X.509 certificate content ...
- 【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
问题描述 在Azure Key Vault中,我们可以从Azure门户中下载证书PEM文件到本地. 可以通过OpenSSL把PFX文件转换到PEM文件.然后用TXT方式查看内容,操作步骤如下图: Op ...
- The thumbprint of same asymmetric key is not same in 'SQL Server Connector for Microsoft Azure Key Vault' 1.0.4.0 and 'SQL Server Connector for Microsoft Azure Key
https://support.microsoft.com/en-us/help/4470999/db-backup-problems-to-sql-server-connector-for-azur ...
- Azure Key Vault (3) 在Azure Windows VM里使用Key Vaule
<Windows Azure Platform 系列文章目录> 本章我们介绍如何在Azure Windows VM里面,使用.NET使用Azure Key Vault 我们需要对Key V ...
- Azure Key Vault (2) 使用Azure Portal创建和查看Azure Key Vault
<Windows Azure Platform 系列文章目录> 请注意: 文本仅简单介绍如何在Azure Portal创建和创建Key Vault,如果需要结合Application做二次 ...
- Azure Key Vault (1) 入门
<Windows Azure Platform 系列文章目录> 为什么要使用Azure Key Vault? 我们假设在微软云Azure上有1个场景,在Windows VM里面有1个.NE ...
- 【Azure Developer】Python代码通过AAD认证访问微软Azure密钥保管库(Azure Key Vault)中机密信息(Secret)
关键字说明 什么是 Azure Active Directory?Azure Active Directory(Azure AD, AAD) 是 Microsoft 的基于云的标识和访问管理服务,可帮 ...
- 【Azure Developer】解决Azure Key Vault管理Storage的示例代码在中国区Azure遇见的各种认证/授权问题 - C# Example Code
问题描述 使用Azure密钥保管库(Key Vault)来托管存储账号(Storage Account)密钥的示例中,从Github中下载的示例代码在中国区Azure运行时候会遇见各种认证和授权问题, ...
- 【Azure 环境】Azure Key Vault (密钥保管库)中所保管的Keys, Secrets,Certificates是否可以实现数据粒度的权限控制呢?
问题描述 Key Vault (密钥保管库) 能不能针对用户授权实现指定用户只能访问某个或某些特定的key? 如当前有两个用户(User1, User2),在Key Vault中有10个Key,Use ...
- Azure Key Vault(二)- 入门简介
一,引言 在介绍 Azure Key Vault 之前,先简单介绍一下 HSM(硬件安全模块). -------------------- 我是分割线 -------------------- 1,什 ...
随机推荐
- PHP中substr() mb_substr() mb_struct()的区别和用法
PHP substr() 函数可以分割文字,但要分割的文字如果包括中文字符往往会遇到问题,这时可以用mb_substr()/mb_strcut这个函 数,mb_substr() /mb_strcut的 ...
- 如何在 Vue 和 JavaScript 中截取视频任意帧图片
如何在 Vue 和 JavaScript 中截取视频任意帧图片 大家好!今天我们来聊聊如何在 Vue 和 JavaScript 中截取视频的任意一帧图片.这个功能在很多场景下都非常有用,比如视频编辑. ...
- AT_abc215_d 题解
洛谷链接&Atcoder 链接 本篇题解为此题较简单做法及较少码量,并且码风优良,请放心阅读. 题目简述 给定 \(N\),\(M\) 及含有 \(N\) 个整数的序列 \(A\). 求 \( ...
- C# EF Core 后端代码已定义的用户实体,如何扩展字段?
注:"2020中国.NET开发者大会"上学习到的开发技巧, 记录下来 1.问题 后端代码已定义的用户实体,如下: public class UserEntity { public ...
- 题解:AT_xmascon21_b Bad Mood
AT_xmascon21_b Bad Mood 题意 给定你一个 \(n\times m\) 的矩形. 以一条对角线为基础上,制作一个无向图,该图的顶点对应于格子的共有 \((m+1) \times ...
- OpenGL之ShadowMap
流程:先创建一个RenderTexture,然后用灯光的视口渲染. 然后切换到正常相机,进行渲染,使用RenderTexture中的深度或者颜色纹理,然后还原当前顶点在灯光中的深度,两者对比,比缓存中 ...
- Java代码实现七夕魔方照片墙
创建一个七夕魔方照片墙是一个相对复杂的任务,涉及到前端展示和后端数据处理.在这里,我会提供一个简化的Java后端示例,用于生成一个模拟的"照片墙"数据模型,并给出一个基本的前端HT ...
- EdgeOne安全专项实践:上传文件漏洞攻击详解与防范措施
前言 今天,我们将深入探讨上传文件漏洞攻击,这部分内容是EdgeOne专项实践篇的一部分.在本章中,我们不会涉及文件漏洞的含义.原理或站点配置等基础教程,如果你对这些内容感兴趣,可以参考这篇文章:探索 ...
- 【JavaWeb】如何越过SpringMVC直接返回内容
来自前同事问的一个问题,因为项目里面的SpringMVC会封装好一个固定的JSON响应规范: 可以看见,data属性下面,又会有一层data, 数据的消费方提出要求,只需要里面data的数据,外面的J ...
- 【H5】06 网页架构
摘自: https://developer.mozilla.org/zh-CN/docs/Learn/HTML/Introduction_to_HTML/%E6%96%87%E4%BB%B6%E5%9 ...