node.js - Forge生成的证书中的签名和解码
问题描述
我正在使用node-forge生成和验证证书
我正在生成和验证证书,一切似乎都运行良好,但是当涉及到我确实需要为证书提供签名的部分时,它失败了
澄清一下:我需要为证书提供签名,其中签名使用RSA进行散列,并且签名包含有关客户端及其角色的数据
我创建签名的方式
const createSignture = (privateKey, data) => {
// The signature method takes the data we want to sign, the
// hashing algorithm, and the padding scheme, and generates
// a signature in the form of bytes
const signature = crypto.sign("sha256", Buffer.from(data), {
key: privateKey,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
});
return signature.toString("base64");
};
当我使用 forge 创建证书时,我正在这样做:
const cert = forge.pki.createCertificate();
....
cert.signature = createSignture(privateKey, userUniqueId);
...
当我验证证书时,我正在尝试验证签名
const verifySignture = (publicKey, signture, data) => {
// To verify the data, we provide the same hashing algorithm and
// padding scheme we provided to generate the signature, along
// with the signature itself, the data that we want to
// verify against the signature, and the public key
return crypto.verify(
"sha256",
Buffer.from(data),
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_PSS_PADDING,
},
signture
);
};
const certSignture = cert.signature;
const decodedSignature = Buffer.from(forge.util.binary.raw.decode(certSignture)).toString("base64");
verifySignture(publicKey, decodedSignature, userUniqueId) // This always returns false
我不太确定我应该在签名中提供角色、用户 ID 等。
我已经尝试了很多小时,但没有任何效果,所以我非常感谢任何帮助
解决方案
推荐阅读
- qt - QML如何通过单击列的标题对tableView进行排序
- android - Flutter:如何在以下文档中检索字段
- jsf - 如何将未定义数量的路径参数映射到 Ocpsoft Rewrite 中的请求参数?
- django - Django:关于使用 get_context_data 扩展 ListView 的两个问题
- python-3.x - 在不使用 numpy 的情况下,在 python 中获取单个 lineby 用户的 3*3 矩阵输入
- php - 如何在 macOSx 中安装 PHP_CodeSniffer?
- python - LinAlgError:不是正定的,即使有抖动
- google-cloud-platform - 如何使用ansible从gcp acount动态库存?
- php - Laravel 包自定义迁移命令
- css - 如何删除 Chrome 中的选择选项黑色边框?