在运行 net472 Web 应用程序的 Azure 应用程序服务中,我从密钥库访问证书,如下所示:
var certSecret = await kvClient.GetSecretAsync(kvName, secretName);
然后我需要发送证书以向外部服务进行身份验证
var cert = new X509Certificate2(Convert.FromBase64String(certSecret.Value));
此行会引发错误
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)