Advertisement
mrAnderson33

Создание и проверка цифровой подписи C# CryptoAPI

Jun 14th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Цифровая_подпись
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             byte[] HashValue = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };
  15.  
  16.             var RSA = new RSACryptoServiceProvider();
  17.  
  18.             var RSAFormatter = new RSAPKCS1SignatureFormatter(RSA);
  19.  
  20.             var RSADeFormatter = new RSAPKCS1SignatureDeformatter(RSA);
  21.  
  22.             RSAFormatter.SetHashAlgorithm("SHA1");
  23.  
  24.             var SignedHashValue = RSAFormatter.CreateSignature(HashValue);
  25.  
  26.             RSADeFormatter.SetHashAlgorithm("SHA1");
  27.  
  28.             if(RSADeFormatter.VerifySignature(HashValue, SignedHashValue))
  29.             {
  30.                 Console.WriteLine("The signature was verified.");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("The signature was not verified.");
  35.             }
  36.         }
  37.     }
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement