c# - -----在 Azure 中运行 faas 时出现 END RSA PRIVATE KEY not found 错误

标签 c# azure docusignapi faas

我使用“DocuSign APS.NET Core Web 应用程序”项目模板创建了一个要在 Azure 中部署的函数即服务,并且在通过我的本地计算机进行测试时它运行良好。

但是,由于私钥错误,当我在 Azure 中测试它时遇到了问题。我使用与本地主机测试中完全相同的字符串,并将其更改为具有不同的换行符转义字符。以下是我不断收到的错误消息:

-----END RSA PRIVATE KEY not found

在本地主机上工作但在 azure 中不起作用的字符串具有以下字符串:

-----BEGIN RSA PRIVATE KEY-----\r\n********\r\n-----END RSA PRIVATE KEY-----

我还尝试了以下 Azure 字符串,但不起作用:

-----BEGIN RSA PRIVATE KEY-----
********
-----END RSA PRIVATE KEY-----

-----BEGIN RSA PRIVATE KEY-----
********
-----END RSA PRIVATE KEY-----

我还在应用程序设置配置中输入了换行符:

-----BEGIN RSA PRIVATE KEY-----
*********
-----END RSA PRIVATE KEY-----

我的代码使用模板提供的 JWTAuth.cs,如下所示:

public static class JWTAuth
{
    /// <summary>
    /// Uses Json Web Token (JWT) Authentication Method to obtain the necessary information needed to make API calls.
    /// </summary>
    /// <returns>A tuple containing the accessToken, accountId and baseUri</returns>
    public static (string, string, string) AuthenticateWithJWT()
    {
        var apiClient = new ApiClient();
        // Get environment variables
        string ik = System.Environment.GetEnvironmentVariable("IntegrationKey", EnvironmentVariableTarget.Process);
        string userId = System.Environment.GetEnvironmentVariable("userId", EnvironmentVariableTarget.Process);  
        string authServer = System.Environment.GetEnvironmentVariable("AuthServer", EnvironmentVariableTarget.Process); 
        string rsaKey = System.Environment.GetEnvironmentVariable("RSAKey", EnvironmentVariableTarget.Process); 

        OAuth.OAuthToken authToken = apiClient.RequestJWTUserToken(ik,
                        userId,
                        authServer,
                        Encoding.UTF8.GetBytes(rsaKey),
                        1);

        //string path = "Resources/PrivateKey.pem";
        //StreamReader pk = File.OpenText(path);

        string accessToken = authToken.access_token;
        apiClient.SetOAuthBasePath(authServer);
        OAuth.UserInfo userInfo = apiClient.GetUserInfo(authToken.access_token);
        Account acct = null;

        var accounts = userInfo.Accounts;
        {
            acct = accounts.FirstOrDefault(a => a.IsDefault == "true");
        }
        string accountId = acct.AccountId;
        string baseUri = acct.BaseUri + "/restapi";
        return (accessToken, accountId, baseUri);
    }
}

如果我可以解决此问题,我希望将应用设置存储在 Azure 的 key 保管库中,作为下一步。

任何帮助将不胜感激。预先感谢您。

最佳答案

如果我们想以 ASCII 编码格式将 ssh key 存储在 KeyVault 中,则可以使用以下命令。

az keyvault secret set –-vault-name <KEY_VAULT_NAME> -–name <NAME_OF_THE_KEY> –-file <PATH_OF_THE_SSH_KEY_FILE> -–encoding ascii

关于c# - -----在 Azure 中运行 faas 时出现 END RSA PRIVATE KEY not found 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60329858/

相关文章:

c# - 如何在 C# 中创建自定义 System.Linq.Expression 类?

azure - 何时使用事件网格以及何时使用服务总线/存储队列?

sql - 有没有办法为 Azure SQL Server 设置默认的 Azure SQL 数据库定价层

node.js - 仅当设置选项卡时,Docusign 请求才返回错误?

json - 如何使用 DocuSign for HTML 格式创建签名请求?

c# - 在资源文件中现有数据的末尾添加数据

c# - 将 IConfiguration 绑定(bind)到 C# 记录类型

docusignapi - 如何在 Docusign 中为数据字段标记换行文本

c#/LINQ - 一段时间内每天、每周和每月的平均查询数

azure - AppService VNet 集成失败