Hash X509 Certificate with SHA 256 in C #

I am working on the implementation of EBICS in C #, and I need to send a hash from my three certificates in SHA256 format to my bank in order to link the EBICS link to it.

I generated them in C # with BouncyCastle, and now I have an object X509Certificate2.

So, to hash my certificate, I used the following code:

String HashCertificate = Certificat.GetCertHashString();

And he returns me the following result:

21952A5F79CA3232A656794EE4532BECF5AE3960

But the length does not match the length of the hash of the bank certificate:

57436AD3D09989ED74F4FCCDBF7668C43F8BF87C933F90B065ED442A22E5B0BF

So, I think the function GetCertHashString()returns a certificate hash in SHA1 format , and I have no idea how I can use it in SHA256 .

Can you help me?

Thank you in advance

+4
1

MSDN GetCertHashString

- SHA1 X.509v3 .

, Windows, certifcates.

, RawData, . SHA256:

using (var hasher = SHA256.Create())
{
    var hash = hasher.ComputeHash(cert.RawData);
    Console.WriteLine(BitConverter.ToString(hash));
}
+6

Source: https://habr.com/ru/post/1623095/


All Articles