Home > Net >  The.net core does not support RSACryptoServiceProvider
The.net core does not support RSACryptoServiceProvider

Time:10-13

In.net core used in RSA signature use PFX when the signature of the certificate file

Unable to cast the object of type 'System. Security. Cryptography. RSACng' to type 'System. Security. Cryptography. RSACryptoServiceProvider'.

 

Try
{
X509Certificate2 PC=new X509Certificate2 (AppDomain. CurrentDomain. BaseDirectory + Config. PrivateLucPath, Config. PrivateLucPwd);

//the OpenSSL. X509Certificate2Provider. BaseCertificateProvider fromFileProvider=new ba
RSACryptoServiceProvider p=(RSACryptoServiceProvider) PC. PrivateKey;

RSA p=(RSA) PC. PrivateKey;

Byte [] enBytes=p. ignData (Encoding UTF8. GetBytes (value), HashAlgorithmName. SHA1, RSASignaturePadding. Pkcs1);
Conviction yourself ispose ();
Return the Convert. ToBase64String (enBytes);

}
The catch (Exception e)
{
//handle exceptions, throw exceptions here Unable to cast the object of type 'System. Security. Cryptography. RSACng' to type 'System. Security. Cryptography. RSACryptoServiceProvider'.

}
return string.Empty;


Excuse me each cow people how to deal with?

CodePudding user response:

Nobody saw yao

CodePudding user response:

Your development reference?

X509Certificate2 PrivateKey type is * AsymmetricAlgorithm *,
AsymmetricAlgorithm may have inherited as follows:
- DSA
- ECDiffieHellman
- ECDsa
- RSA

And the realization of a RSA (current) :
- RSACng
- RSACryptoServiceProvider
- RSAOpenSsl

Don't discuss here "using a PFX certificate" to import the key whether appropriate, but for your code, you want to whether PrivateKey RSA , if it is, using the RSA abstract classes to sign, rather than blindly use RSACryptoServiceProvider,

CodePudding user response:

The author has solved the excuse me? In dealing with the problem I also don't know how the core signing certificate very urgent!!!!!

CodePudding user response:

Well I'd better reply to world peace, hope everyone have a good life, day day up cao!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 var PC=new X509Certificate2 (priKeyFile, keyPwd, X509KeyStorageFlags MachineKeySet | X509KeyStorageFlags. PersistKeySet | X509KeyStorageFlags. An Exportable); 
Var rsaParam=PC. GetRSAPrivateKey (.) ExportParameters (true);
Var rsa=new RSACryptoServiceProvider ();
Rsa. ImportParameters (rsaParam);
Byte [] data1=Encoding. UTF8. GetBytes (data);
SHA256CryptoServiceProvider sha256=new SHA256CryptoServiceProvider ();
Byte [] bCrypto=sha256.Com puteHash (data1);
Var halg=new SHA256CryptoServiceProvider ();
Byte [] inArray=rsa. SignData (bCrypto, "SHA256");
//signed Base64
Return the Convert. ToBase64String (inArray);
  •  Tags:  
  • C#
  • Related