【发布时间】:2015-07-29 06:15:22
【问题描述】:
我有这个辅助方法:
CngKeyCreationParameters keyParams = new CngKeyCreationParameters();
keyParams.KeyCreationOptions = CngKeyCreationOptions.None;
keyParams.KeyUsage = CngKeyUsages.Signing;
keyParams.Provider = CngProvider.MicrosoftSoftwareKeyStorageProvider;
keyParams.ExportPolicy = CngExportPolicies.AllowExport;
String newguid = Guid.NewGuid().ToString();
CngKey newKey = CngKey.Create(CngAlgorithm2.Rsa, keyParams);
...
我调试的时候(我的本地机器),一切正常,但是在生产环境中,最后一句CngKey newKey = CngKey.Create(CngAlgorithm2.Rsa, keyParams);抛出如下异常:“系统找不到指定的文件。”
主要思想是创建一个自签名证书 (x509) 来存储它并使用它来签署 PDF 文档。
更新:
StackTrace(使用:CngKeyCreationOptions.None):
[CryptographicException: The system cannot find the file specified.
]
System.Security.Cryptography.NCryptNative.CreatePersistedKey(SafeNCryptProviderHandle provider, String algorithm, String name, CngKeyCreationOptions options) +2244958
System.Security.Cryptography.CngKey.Create(CngAlgorithm algorithm, String keyName, CngKeyCreationParameters creationParameters) +248
StackTrace(使用:CngKeyCreationOptions.MachineKey):
[CryptographicException: Access denied.
]
System.Security.Cryptography.NCryptNative.FinalizeKey(SafeNCryptKeyHandle key) +2243810
System.Security.Cryptography.CngKey.Create(CngAlgorithm algorithm, String keyName, CngKeyCreationParameters creationParameters) +266
【问题讨论】:
-
我们能得到那个异常的堆栈跟踪吗?请提供更多详细信息。
-
尝试将
CngKeyCreationOptions设置为MachineKey而不是None。我认为 Azure 将您的服务作为没有用户配置文件的帐户运行,这意味着没有加密存储。您还可能会遇到使用机器密钥集的权限问题 - azure Web 应用程序可能不允许您使用机器密钥存储。 -
谢谢![CryptographicException:访问被拒绝。 ] System.Security.Cryptography.NCryptNative.FinalizeKey(SafeNCryptKeyHandle key) +2243810 System.Security.Cryptography.CngKey.Create(CngAlgorithm algorithm, String keyName, CngKeyCreationParameters creationParameters) +266
标签: asp.net-mvc certificate azure-web-app-service x509