Процесс верификации сертификата цифровой подписи с помощью pdf-файла ASP.NET и с#
Привет Разработчикам
как сгенерировать сертификат цифровой подписи, а также проверить открытый и закрытый ключи с помощью C# any one know share me.
Надеюсь, с Savadamuthu сараванан.
Что я уже пробовал:
class X509CertTest { static void Main(string[] args) { string messageToFatima = "My personal data"; //13 //14 //retrieve certificate from store// //15 X509Certificate2 certificate = GetCertFromStore(); //16 //17 //**signing data**// //18 byte[] hashBytes = GetDataHash(messageToFatima); byte[] signature= GetDigitalSignature(hashBytes); //24 bool isVerified = VerifyData(signature, messageToFatima); //25 //26 Console.WriteLine("IsVerified: {isVerified}"); Console.ReadLine(); } private static bool VerifyData(byte[] signature, string messageFromAhemd) { //33 var messageHash = GetDataHash(messageFromAhemd); //34 //35 X509Certificate2 certificate = GetCertFromStore(); RSACryptoServiceProvider cryptoServiceProvider=(RSACryptoServiceProvider)certificate.PublicKey.Key; return cryptoServiceProvider.VerifyHash(messageHash, CryptoConfig.MapNameToOID("SHA1"), signature); } private static byte[] GetDigitalSignature(byte[] hashBytes) { X509Certificate2 certificate = GetCertFromStore(); /*use any asymmetric crypto service provider for encryption of hash 46 with private key of cert. 47 */ RSACryptoServiceProvider rsaCryptoService = (RSACryptoServiceProvider) certificate.PrivateKey; /*now lets sign the hash 51 1.spevify hash bytes 52 2. and hash algorithm name to obtain the bytes 53 */ //54 return rsaCryptoService.SignHash(hashBytes,CryptoConfig.MapNameToOID("SHA1") ); } private static byte[] GetDataHash(string sampleData) { SHA1Managed managedHash=new SHA1Managed(); return managedHash.ComputeHash(Encoding.Unicode.GetBytes(sampleData)); } private static X509Certificate2 GetCertFromStore() { //to access to store we need to specify store name and location X509Store x509Store = new X509Store("sampleCertStore",StoreLocation.CurrentUser); //obtain read only access to get cert //71 x509Store.Open(OpenFlags.ReadOnly); //72 //73 return x509Store.Certificates[1]; } }