M
M
Multigame2018-05-06 19:27:27
C++ / C#
Multigame, 2018-05-06 19:27:27

How does RSA+SHA1 digital signature work? How to implement in C#?

Good afternoon!
We integrate with a payment gateway that uses RSA+SHA1 EDS to verify communication with X509 certificates. We have generated a private key + certificate, which we sent to the gateway. The gateway in response generated a certificate on its side and sent two files, CRT and KEY (contains a public key). As far as I understand the signature algorithm, when sending, we first read RSA from the content being signed, using their certificate (public key?), Then we read the sha1 hash from the received cipher. Question:
1) Have I described the process correctly? or are there more steps I'm missing?
2) Does the certificate contain a public key? if so, is the KEY file sent by the gateway needed?
Practical part.
The implementation is done in C#.

var content = "data";
var ctr = new X509Certificate2(filename); // путь до crt-файла присланного шлюзом
var provider = ctr.PublicKey.Key as RSACryptoServiceProvider; // если после этой строки посмотрим на provider, то там действительно есть сертификат длинной 2048
var dta = provider.Encrypt(Encoding.ASCII.GetBytes(content), true); // в dta вроде бы 256 байт
var sig = provider.SignData(dta, "SHA1");  // и тут мы ловим исключение "набор ключей не существует"

1) What am I doing wrong? Is there a key?
2) if the content is longer than 2048 bytes, then I suppose there will be problems at the stage of obtaining the RSA cipher. Is there a mechanism to overcome this problem? or the only solution is the initial generation of keys 16kb long (well, that is, longer)?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Multigame, 2018-05-06
@Multigame

"Keyset does not exist" error - signing occurs using the Private Key. Therefore, it must be loaded in the same way as the certificate.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question