Can RSACryptoServiceProvider (.NET's RSA) use SHA256 for encryption (not signing) instead of SHA1?

前端 未结 6 1565
渐次进展
渐次进展 2020-12-15 08:11

When encrypting, can RSACryptoServiceProvider (or any other RSA encryptor available from .NET) use SHA256 instead of SHA1?

SHA1 appears to be hard coded with no way

6条回答
  •  無奈伤痛
    2020-12-15 08:35

    Just for reference: How to change the CSP within a .p12 or .pfx (certificate with private key). You need the password for the private key within the .pfx in order to do the following steps.

    Step 1: Convert the file into open format temp.pem

    openssl pkcs12 -in myCert.p12 -out temp.pem -passin pass:myPassword -passout pass:temppwd
    

    or openssl pkcs12 -in myCert.pfx -out temp.pem -passin pass:myPassword -passout pass:temppwd

    Step 2: Create file myCert2.pfx containing the CSP reference needed for Windows

    openssl pkcs12 -export -in temp.pem -out myCert2.pfx -CSP "Microsoft Enhanced RSA and AES Cryptographic Provider" -passin pass:temppwd -passout pass:myPassword
    

    Step 3: Delete temp.pem. It's no longer needed.

    del temp.pem
    

    Step 4: Verify it is done correctly

    openssl pkcs12 -info -nodes -in myCert2.pfx -passin pass:myPassword
    

    This must show Microsoft CSP Name: Microsoft Enhanced RSA and AES Cryptographic Provider

    With such a modified certificate you can use the 1st code in Kastorskijs answer.

提交回复
热议问题