【Azure Developer】使用Azure Key Vault 的Key签名后,离线验证的一些参考资料
问题描述
使用 key Vault 的sign接口,Request Body中的 Value 是要传什么呢? 签名后的内容如何在本地离线验证呢?
Azure Key Vault Sign 接口:https://docs.microsoft.com/zh-cn/rest/api/keyvault/sign/sign#jsonwebkeysignaturealgorithm
问题答案
Azure Key Vault Sign 方法的目的是:使用指定的键从摘要创建签名。它的Body中Value的值为使用Base64编码后的内容.

签名并验证:严格来讲,此操作应该为“签名哈希”或“验证哈希”,因为 Key Vault 不支持创建签名过程中的内容哈希。 所以需要在调用Sign方法前,进行内容哈希,然后请求 Key Vault 对哈希内容进行签名。
- 支持签名哈希的验证,作为可能无法访问 [公共] 密钥材料的应用程序的一种便捷操作。 为获得最佳应用程序性能,应在本地执行 VERIFY 操作。关于密钥签名并验证请参考:https://docs.azure.cn/zh-cn/key-vault/keys/about-keys-details#key-operations
- RSASSA-PKCS-v1_5 使用 SHA-256。 必须使用 SHA-256 计算应用程序提供的摘要值,并且该值的长度必须为 32 字节。关于RS256的要求请参考:https://docs.azure.cn/zh-cn/key-vault/keys/about-keys-details#signverify
- 关于密钥、机密和证书请参考:https://docs.azure.cn/zh-cn/key-vault/general/about-keys-secrets-certificates
C#的本地离线签名验证代码:

Git Hub链接为:https://github.com/rahulpnath/Blog/blob/master/VerifySignatureOffline/VerifySignatureOffline/Program.cs , 如不能访问,可以参考以下的部分源码:
using Microsoft.Azure.KeyVault;
using Microsoft.Azure.KeyVault.WebKey;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks; namespace VerifySignatureOffline
{
class Program
{
private static string applicationId = "ApplicationID";
private static string applicationSecret = "ApplicationSecret";
static void Main(string[] args) {
var client = new KeyVaultClient(Authenticate);
GetKeys(client);
Console.ReadKey();
} private static async Task<string> GetKeys(KeyVaultClient keyVaultClient)
{
var keyIdentifier = "keyIdentifier"; var textToEncrypt = "This is a test message";
var byteData = Encoding.Unicode.GetBytes(textToEncrypt);
var hasher = new SHA256CryptoServiceProvider();
var digest = hasher.ComputeHash(byteData);
var signedResult = await keyVaultClient.SignAsync(
keyIdentifier, JsonWebKeySignatureAlgorithm.RS256, digest); var isVerified = await keyVaultClient.VerifyAsync(keyIdentifier, "RS256", digest, signedResult.Result); var keyResult = await keyVaultClient.GetKeyAsync(keyIdentifier);
var jsonWebKey = keyResult.Key.ToString(); var key = JsonConvert.DeserializeObject<JsonWebKey>(jsonWebKey);
var rsa = new RSACryptoServiceProvider();
var p = new RSAParameters() { Modulus = key.N, Exponent = key.E };
rsa.ImportParameters(p); isVerified = rsa.VerifyHash(digest, "Sha256", signedResult.Result);
return null;
} private static async Task<string> Authenticate(string authority, string resource, string scope)
{
var adCredential = new ClientCredential(applicationId, applicationSecret);
var authenticationContext = new AuthenticationContext(authority, null);
return (await authenticationContext.AcquireTokenAsync(resource, adCredential)).AccessToken;
}
}
}
原文参考 Azure Key Vault: Digital Signatures and Offline Verification : https://www.rahulpnath.com/blog/azure-key-vault-digital-signatures-and-offline-verification/
【Azure Developer】使用Azure Key Vault 的Key签名后,离线验证的一些参考资料的更多相关文章
- 【Azure Developer】Azure Automation 自动化账号生成的时候怎么生成连接 与证书 (Connection & Certificate)
Azure Automation :The Azure Automation service provides a highly reliable and scalable workflow exec ...
- 【Azure Developer】Azure Graph SDK获取用户列表的问题: SDK中GraphServiceClient如何指向中国区的Endpoint:https://microsoftgraph.chinacloudapi.cn/v1.0
问题描述 想通过Java SDK的方式来获取Azure 门户中所列举的用户.一直报错无法正常调用接口,错误信息与AAD登录认证相关,提示tenant not found. 想要实现的目的,通过代码方式 ...
- 【Azure Developer】Azure Logic App 示例: 解析 Request Body 的 JSON 的表达式? triggerBody()?
问题描述 通过Azure Logic App(逻辑应用)实现无代码的处理JSON数据.但是如何获取Request Body中的一个属性值呢? 例如:如何来获取以下JSON结构中的 ObjectName ...
- 【Azure Developer】解决Azure Key Vault管理Storage的示例代码在中国区Azure遇见的各种认证/授权问题 - C# Example Code
问题描述 使用Azure密钥保管库(Key Vault)来托管存储账号(Storage Account)密钥的示例中,从Github中下载的示例代码在中国区Azure运行时候会遇见各种认证和授权问题, ...
- 【Azure Developer】Python代码通过AAD认证访问微软Azure密钥保管库(Azure Key Vault)中机密信息(Secret)
关键字说明 什么是 Azure Active Directory?Azure Active Directory(Azure AD, AAD) 是 Microsoft 的基于云的标识和访问管理服务,可帮 ...
- 【Azure Developer - 密钥保管库 】使用 Python Azure SDK 实现从 Azure Key Vault Certificate 中下载证书(PEM文件)
问题描述 在Azure Key Vault中,我们可以从Azure门户中下载证书PEM文件到本地. 可以通过OpenSSL把PFX文件转换到PEM文件.然后用TXT方式查看内容,操作步骤如下图: Op ...
- 【Azure Developer】使用 CURL 获取 Key Vault 中 Secrets 中的值
问题描述 在使用CURL通过REST API获取Azure Key Vaualt的Secrets值,提示Missing Token, 问如何来生成正确的Token呢? # curl 命令 curl - ...
- 【Azure Developer】记录一次使用Java Azure Key Vault Secret示例代码生成的Jar包,单独运行出现 no main manifest attribute, in target/demo-1.0-SNAPSHOT.jar 错误消息
问题描述 创建一个Java Console程序,用于使用Azure Key Vault Secret.在VS Code中能正常Debug,但是通过mvn clean package打包为jar文件后, ...
- 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 ...
随机推荐
- 部分操作系统不支持 zip unzip 大于4G的文件.
https://www.ibm.com/mysupport/s/question/0D50z00006PD9XXCA1/bad-zipfile-offset-local-header-sig-erro ...
- Chrome 历史版本下载点
https://www.chromedownloads.net/chrome64win-stable/
- vue3.0中reactive的正确使用姿势
场景 在项目开发的时候,前端肯定是先写静态页面 在静态页面写好之后 然后就可以与后端对接数据了[高兴] 但是在对接接口的时候 我们会发现后端返回来的字段与前端在页面上写的可能不一致 这个时候有意思的事 ...
- MySQL知识点总结(完整版)
MySQL学习笔记 登录和退出MySQL服务器 # 登录MySQL $ mysql -u root -p12345612 # 退出MySQL数据库服务器 exit; 基本语法 -- 显示所有数据库 s ...
- Couldn't launch Python exit code 9009
Couldn't launch Python exit code 9009 start stable-diffusion-webui,发现,python 环境没有,我本地其实是已经安装完毕的,后来发现 ...
- Redis安装,数据类型及常用命令
安装 - 可以使用yum 安装,要先配置epel源 ``` yum install -y redis ``` - 可以编译安装 ``` wget http://download.redis.io/re ...
- django向数据库更新时间
1 今天的日期可以用下面的代码: 2 3 import datetime 4 5 today = datetime.date.today() 6 7 8 9 得到昨天的日期可以用: 10 11 yes ...
- axios请求失败,获取接口返回错误信息
一般vue项目都会对axios进行封装,后台统一规范默认让服务器对所有请求都返回成功,然后在成功的对象里面包装一层对象result,里面也包含code,msg,result信息,前端拿这个result ...
- 《ASP.ENT Core 与 RESTful API 开发实战》(第3章)-- 读书笔记(中)
第 3 章 ASP.NET Core 核心特性 3.3 依赖注入 通常情况下,应用程序由多个组件构成,而组件与组件之间往往存在依赖关系 当我们需要获取数据时,通常的做法是实例化依赖的类,然后调用类里面 ...
- 《ASP.NET Core 微服务实战》-- 读书笔记(第5章)
第 5 章 创建数据服务 选择一种数据存储 由于我坚持要尽可能的跨平台,所以我决定选用 Postgres,而不用 SQL Server 以照顾 Linux 或 Mac 电脑的读者 构建 Postgre ...