Azure Functions (Node.js):如何从代码读取上传到 Azure 上证书刀片的公钥 (.cer)?

问题描述 投票:0回答:1

我在 Node.js 上运行 Azure Functions。 (另请注意,通过应用服务计划的底层操作系统是 Windows


我先绕一点路吧

我一直在通过 Node.js 代码访问 Azure Key Vault,所以我知道如何从 Node.js 代码访问 Key Vault,所以它看起来像这样:

const { DefaultAzureCredential } = require("@azure/identity");
const { SecretClient } = require("@azure/keyvault-secrets");
const AzureCredential = new DefaultAzureCredential();
const kvEndpoint = "Key Vault Endpoint Url";
const kvClient = new SecretClient(kvEndpoint, AzureCredential);
const API_KEY = (await kvClient.getSecret("Key Name")).value;

但这只是 Azure Key Vault,这不是我正在寻找的东西。我分享上述代码的原因是为了强调,从 Node.js 连接到 Azure Key Vault 也非常简单。为此,Node.js 包已完成。

现在。

我想读取直接上传到 Azure Function App 仪表板本身的证书边栏选项卡的“公钥”(.cer)。 (不是 Key Vault 中的那个)。上传后是这样的:

enter image description here 问题

如何从 Node.js 读取公钥 (.cer)?我真的尝试阅读 Microsoft 的

可用文档

,但他们提到的所有文档仅适用于 C# 和 Java。 非常感谢所有帮助。

node.js azure azure-functions public-key
1个回答
0
投票
document

中获取代码来获取 Azure function App=>Certificates=>Public Key Certificates(.cer) 下可用的证书:

enter image description here

添加应用程序设置
    WEBSITE_LOAD_CERTIFICATES
  • ,其中包含证书的指纹或
    *
    作为其在
    Function App=>Environment Variables
    中的值:
    
    

enter image description here

代码片段:

const http = require('http'); const ca = require('win-ca'); // Create an instance of the http server to handle HTTP requests let app = http.createServer((req, res) => { // Set a response type of plain text for the response res.writeHead(200, { 'Content-Type': 'text/plain' }); // fetching certificates let certificates = [] ca({ format:ca.der2.pem, store: ['My'], ondata: crt => certificates.push(crt) }) res.end("Certificate count under 'My' store is" + certificates); }); let port = process.env.PORT || 3000; app.listen(port); console.log('Node server running on port ' + port);

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.