<link>http://www.ncryptoki.com/forum.aspx</link> <description /> <docs>http://www.rssboard.org/rss-specification</docs> <generator>mojoPortal Forum module</generator> <item> <title>Re: Digital Signature using the RSA encryption algorithm I think I need to find a match for "HashAlgorithmName.SHA256 and RSASignaturePadding.Pkcs1"?

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=345~-1#post1191 Andy Mezentsev http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 12 Jan 2021 06:27:34 GMT Digital Signature using the RSA encryption algorithm Good day!
Thank you for your attention, I really need help.

Before using NKryptoki, I had the following signature code:

    private static string _GenerateDigitalSignature (string body, string privateKeyText)
    {
        var hash = HashBody (body);

        byte [] signedHash;
        using (var privateKey = ImportPrivateKey (privateKeyText))
        {
            signedHash = privateKey.SignHash (hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
        }

        var encodedHash = Convert.ToBase64String (signedHash);

        return encodedHash;
    }

        private static byte [] HashBody (string content)
    {
        var contentBytes = Encoding.UTF8.GetBytes (content);

        using (var provider = new SHA256Managed ())
        {
            var hash = provider.ComputeHash (contentBytes);

            return hash;
        }
    }

    private static RSACryptoServiceProvider ImportPrivateKey (string pem)
    {
        StringReader sr = new StringReader (pem);
        PemReader pr = new PemReader (sr);
        AsymmetricKeyParameter Key;
        Key = (AsymmetricKeyParameter) pr.ReadObject ();
        pr.Reader.Close ();
        sr.Close ();
        var rsaParameters = DotNetUtilities.ToRSAParameters ((RsaPrivateCrtKeyParameters) Key);
        var csp = new RSACryptoServiceProvider ();
        csp.ImportParameters (rsaParameters);
        return csp;
    }

Which signature mechanism should I choose so that the results match?
Very much I ask for your advice!

]]>
http://www.ncryptoki.com/Forums/Thread.aspx?pageid=9&t=345~-1#post1190 Andy Mezentsev http://www.ncryptoki.com/Forums/Thread.aspx?pageid= Tue, 12 Jan 2021 06:16:15 GMT