Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在Azure AppService中获取X509Certificate2.PrivateKey时出错_C#_Azure_Certificate_X509certificate - Fatal编程技术网

C# 在Azure AppService中获取X509Certificate2.PrivateKey时出错

C# 在Azure AppService中获取X509Certificate2.PrivateKey时出错,c#,azure,certificate,x509certificate,C#,Azure,Certificate,X509certificate,几个小时前,我还以为这是一场灾难 但我将调试程序连接到Azure AppService网站,发现PrivateKey有一个问题: 如果运行相同的证书,但在localhost中私钥工作良好: 尝试获取certificate.PrivateKey属性时的异常详细信息: System.Security.Cryptography.CryptographyException:指定的提供程序类型无效。 在System.Security.Cryptography.Utils.CreateProvHandl

几个小时前,我还以为这是一场灾难

但我将调试程序连接到Azure AppService网站,发现PrivateKey有一个问题:

如果运行相同的证书,但在localhost中私钥工作良好:

尝试获取certificate.PrivateKey属性时的异常详细信息:
System.Security.Cryptography.CryptographyException:指定的提供程序类型无效。
在System.Security.Cryptography.Utils.CreateProvHandle(CspParameters参数,布尔随机密钥容器)
在System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType、CspParameters parameters、Boolean randomKeyContainer、Int32 dwKeySize、SafeProvHandle和SafeProvHandle、SafeKeyHandle和SafeKeyHandle)
在System.Security.Cryptography.rsacyptoServiceProvider.GetKeyPair()中
在System.Security.Cryptography.RSACryptServiceProvider..ctor(Int32 dwKeySize、CspParameters、Boolean useDefaultKeySize)
在System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()

当我尝试certificate.GetRSAPrivateKey()方法时:

初始化证书的方式如下:

public X509Certificate2 GetCertificate(byte[] pBytes,string pPassword)
{
        X509Certificate2 vCertificate = null;
        try
        {
            vCertificate = new X509Certificate2(pBytes,pPassword);
        }
        catch(Exception ex)
        {
            throw ex
        }
        return vCertificate
}
.Net版本框架是v4.7

那么我需要在Azure配置中配置一些东西吗? 有线索吗

不要认为这是重复的:


它看起来像是Azure限制、配置或类似的东西。

我认为由于Web应用的体系结构,您将无法访问该WinAPi。您需要使用cert.GetRSAPrivateKey()()可能与使用cert.GetRSAPrivateKey()重复,我收到了相同的错误:System.Security.Cryptography.CryptographyException:提供程序类型无效specified@bartonjs-我在Azure上也有同样的问题,同样的代码在我的机器上运行良好,但在Azure应用程序服务上不起作用。
public X509Certificate2 GetCertificate(byte[] pBytes,string pPassword)
{
        X509Certificate2 vCertificate = null;
        try
        {
            vCertificate = new X509Certificate2(pBytes,pPassword);
        }
        catch(Exception ex)
        {
            throw ex
        }
        return vCertificate
}