【发布时间】:2011-01-16 16:30:54
【问题描述】:
我在尝试使用 ASP.NET (.NET 4) 为 RSA 生成密钥时遇到问题,RSACryptoServiceProvider 会抛出无效标志指定异常。
[CryptographicException:指定的标志无效。 ] System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 小时)+33 System.Security.Cryptography.Utils._GenerateKey(SafeProvHandle hProv, Int32 algid, CspProviderFlags flags, Int32 keySize, SafeKeyHandle& hKey) +0 System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters 参数, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle) +9719339 System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() +89 System.Security.Cryptography.RSACryptoServiceProvider.ExportParameters(Boolean includePrivateParameters) +38 System.Security.Cryptography.RSA.ToXmlString(Boolean includePrivateParameters) +45
我使用以下代码初始化 RSA:
var _cpsParameter = new CspParameters();
_cpsParameter.Flags = CspProviderFlags.UseMachineKeyStore;
var rsaProvider = new RSACryptoServiceProvider(bitStrength, _cpsParameter);
string publicAndPrivateKeys = rsaProvider.ToXmlString(true);
string justPublicKey = rsaProvider.ToXmlString(false);
知道如何解决这个问题吗?
【问题讨论】:
-
bitStrength 值是多少?
标签: asp.net cryptography