RSA key signature

Just starting out? Need help? Post your questions and find answers here.
Lima
User
User
Posts: 40
Joined: Tue Jul 14, 2015 2:52 pm

RSA key signature

Post by Lima »

I use the following method in C#, which through PB 'Runprogram' transmit the data and get the result.
The method receives the "content to sign"

C#
public Static string CalculateHash (string ContentToSign)
{

RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider ();
rsaCSP.FromXmlString (privateKeyXml); // (privateKeyXml = RSA private Key in XML format)
Byte [] buffer = Encoding.GetEncoding ("UTF-8"). GetBytes (ContentToSign);
Byte [] signature = rsaCSP.SignData (buffer, "SHA1");
string hash = Convert.ToBase64String (signature);

Return hash;
}

The same result can be obtained with Openssl as follows:
echo "content to sign" | openssl dgst -sha1 -sign PrivateKey.pem | openssl enc -base64 -out hash.txt
(here the RSA private key is in PEM format)

My request for help is whether it will be possible to get the same result with PB code.

In advance my great thanks to all who can and will be available to respond.
infratec
Always Here
Always Here
Posts: 6871
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: RSA key signature

Post by infratec »

An example of data, key and hash would be helpful.

How should we see if the result is identical?
I don't use C# and on windows I don't have openssl installed.
Lima
User
User
Posts: 40
Joined: Tue Jul 14, 2015 2:52 pm

Re: RSA key signature

Post by Lima »

Thanks infratec

with this example
echo "2010-03-11;2010-03-11T11:27:08;FAC 001/9;1200.00;" | openssl dgst -sha1 -sign PrivateKey.pem | openssl enc -base64 -out signhash64.txt

being the file 'PrivateKey.pem'
-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQDCbKxbJSh5xAgKuglznGbSSHIAe6dX6DX/Ty6gWiByPYRfPuEl
zVl4h84WxMaVeuNjBOugCtPX/RtJd0xwkkimimQXYyDv/42IApum9Q/ihHtk3dYQ
5KwfCQOW3G8DHb4tWXWTMexjSrsbHVCqkArWHIjY11VFbm/3ePSGFaHP3QIDAQAB
AoGBAIvAmdOaThHYuv8a4phbn/0fXfLC73Lc05OFUzqoDhKP7YqZJDWL+fgNhjIP
l77y6mfOraAIq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