示例#1
0
 /// <summary>
 ///     Подпись хэша.
 /// </summary>
 /// <param name="hash">Хэш.</param>
 /// <param name="keyNumber">Тип ключа.</param>
 /// <returns>Подпись хэша.</returns>
 public byte[] SignHash(byte[] hash, KeyNumber keyNumber)
 {
     using (HashContext hashContext = CreateHash(null, Constants.CpcspHashId, 0))
     {
         hashContext.SetHashParameter(Constants.HpHashValue, hash, 0);
         return(hashContext.SignHash(keyNumber, 0));
     }
 }
示例#2
0
 public byte[] ComputeHash(byte[] data)
 {
     using (var facade = new GostCryptFacade(ProviderParams))
     {
         facade.AcquireContext(null, Constants.CryptVerifycontext);
         using (HashContext hashContext = facade.CreateHash(null, 0))
         {
             hashContext.AddData(data, 0);
             return(hashContext.GetValue());
         }
     }
 }
示例#3
0
 /// <summary>
 ///     Подсчет хэша.
 /// </summary>
 /// <param name="data">Данные.</param>
 /// <returns>Хэш.</returns>
 public static byte[] ComputeHash(byte[] data)
 {
     using (var container = new KeyContainer())
     {
         container.AcquireContext(null, ProviderName, ProviderType, Constants.CryptVerifycontext);
         using (HashContext hashContext = container.CreateHash(null, Constants.CpcspHashId, 0))
         {
             hashContext.AddData(data, 0);
             return(hashContext.GetValue());
         }
     }
 }
示例#4
0
        /// <summary>
        ///     Проверяеи ЭЦП данных.
        /// </summary>
        /// <param name="signature">Подпись (ЭЦП).</param>
        /// <param name="hashContext">Контекст хэша данных.</param>
        /// <param name="flags">Дополнительные управляющие флаги.</param>
        /// <returns>True, если ЭЦП корректна.</returns>
        public bool VerifySignature(byte[] signature, HashContext hashContext, int flags)
        {
            if (CryptoApi.CryptVerifySignature(hashContext.Handler, signature, signature.Length, handler, null, flags))
            {
                return(true);
            }

            if (Marshal.GetLastWin32Error() == Constants.NteBadSignature)
            {
                return(false);
            }

            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
示例#5
0
        /// <summary>
        ///     Проверяеи ЭЦП данных.
        /// </summary>
        /// <param name="signature">Подпись (ЭЦП).</param>
        /// <param name="hashContext">Контекст хэша данных.</param>
        /// <param name="flags">Дополнительные управляющие флаги.</param>
        /// <returns>True, если ЭЦП корректна.</returns>
        public bool VerifySignature(byte[] signature, HashContext hashContext, int flags)
        {
            if (CryptoApi.CryptVerifySignature(hashContext.Handler, signature, signature.Length, handler, null, flags))
            {
                return true;
            }

            if (Marshal.GetLastWin32Error() == Constants.NteBadSignature)
            {
                return false;
            }

            throw new Win32Exception(Marshal.GetLastWin32Error());
        }
示例#6
0
 /// <summary>
 ///     Проверка подписи.
 /// </summary>
 /// <param name="signature">Подпись.</param>
 /// <param name="data">Данные.</param>
 /// <param name="certificateData">Сертификат.</param>
 /// <returns>True - провека прошла успешно, иначе False.</returns>
 public static bool VerifyCertificate(byte[] signature, byte[] data, byte[] certificateData)
 {
     using (var container = new KeyContainer())
     {
         container.AcquireContext(null, ProviderName, ProviderType, Constants.CryptVerifycontext);
         using (KeyContext keyContext = container.ImportSertificate(certificateData))
         {
             using (HashContext hashContext =
                        container.CreateHash(null, Constants.CpcspHashId, 0))
             {
                 hashContext.AddData(data, 0);
                 return(keyContext.VerifySignature(signature, hashContext, 0));
             }
         }
     }
 }
示例#7
0
 public bool VerifyCertificate(
     byte[] signature,
     byte[] data,
     byte[] certificateData)
 {
     using (var facade = new GostCryptFacade(ProviderParams))
     {
         facade.AcquireContext(null, Constants.CryptVerifycontext);
         using (KeyContext keyContext = facade.ImportSertificate(certificateData))
         {
             using (HashContext hashContext = facade.CreateHash(null, 0))
             {
                 hashContext.AddData(data, 0);
                 return(keyContext.VerifySignature(signature, hashContext, 0));
             }
         }
     }
 }
示例#8
0
 public bool VerifySignature(
     byte[] signature,
     byte[] data,
     byte[] publicKey)
 {
     using (var facade = new InfotecsFacade(ProviderParams))
     {
         facade.AcquireContext(null, Constants.CryptVerifycontext);
         using (KeyContext keyContext = facade.ImportKey(null, publicKey, 0))
         {
             using (HashContext hashContext = facade.CreateHash(null, 0))
             {
                 hashContext.AddData(data, 0);
                 return(keyContext.VerifySignature(signature, hashContext, 0));
             }
         }
     }
 }
示例#9
0
        private HashContext CreateHash(KeyContext keyContext, int algid, int flags)
        {
            IntPtr hashHandler = IntPtr.Zero;
            IntPtr keyHandler  = IntPtr.Zero;

            if (keyContext != null)
            {
                keyHandler = keyContext.Handler;
            }

            if (!CryptoApi.CryptCreateHash(cspHandler, algid, keyHandler, flags, ref hashHandler))
            {
                throw new Win32Exception();
            }

            var hashContext = new HashContext(hashHandler);

            return(hashContext);
        }
示例#10
0
        private HashContext CreateHash(KeyContext keyContext, int algid, int flags)
        {
            IntPtr hashHandler = IntPtr.Zero;
            IntPtr keyHandler = IntPtr.Zero;

            if (keyContext != null)
            {
                keyHandler = keyContext.Handler;
            }

            if (!CryptoApi.CryptCreateHash(cspHandler, algid, keyHandler, flags, ref hashHandler))
            {
                throw new Win32Exception();
            }

            var hashContext = new HashContext(hashHandler);
            return hashContext;
        }