Ejemplo n.º 1
0
        private static SafeHashHandleCP SetupHashAlgorithm(SafeProvHandleCP prov, byte[] rgbHash, int algId)
        {
            SafeHashHandleCP invalidHandle = SafeHashHandleCP.InvalidHandle;

            CreateHash(prov, algId, ref invalidHandle);

            uint num = 0;

            if (!CApiExtWin.CryptGetHashParam(invalidHandle, 2, null, ref num, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            if ((ulong)((int)rgbHash.Length) != (ulong)num)
            {
                throw new CryptographicException(-2146893822);
            }

            if (!CApiExtWin.CryptSetHashParam(invalidHandle, 2, rgbHash, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            return(invalidHandle);
        }
Ejemplo n.º 2
0
 internal static void CreateHash(SafeProvHandleCP hProv, int algid, ref SafeHashHandleCP hHash)
 {
     if (!CApiExtWin.CryptCreateHash(hProv, (uint)algid, SafeKeyHandleCP.InvalidHandle, (uint)0, ref hHash))
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
 }
Ejemplo n.º 3
0
        public HashAlgGost2001Win()
        {
            this.HashSizeValue = Gost3411Consts.HashSizeValue;
            SafeHashHandleCP invalidHandle = SafeHashHandleCP.InvalidHandle;

            Win32ExtUtil.CreateHash(Win32ExtUtil.StaticGost2001ProvHandle, Gost3411Consts.HashAlgId, ref invalidHandle);
            this.safeHashHandle = invalidHandle;
        }
Ejemplo n.º 4
0
        public override void Initialize()
        {
            if (this.safeHashHandle != null &&
                !this.safeHashHandle.IsClosed)
            {
                this.safeHashHandle.Dispose();
            }

            SafeHashHandleCP invalidHandle = SafeHashHandleCP.InvalidHandle;

            Win32ExtUtil.CreateHash(Win32ExtUtil.StaticGost2001ProvHandle, Gost3411Consts.HashAlgId, ref invalidHandle);
            this.safeHashHandle = invalidHandle;
        }
Ejemplo n.º 5
0
        internal static byte[] EndHash(SafeHashHandleCP hHash)
        {
            uint num = 0;

            if (!CApiExtWin.CryptGetHashParam(hHash, 2, null, ref num, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            byte[] numArray = new byte[num];
            if (!CApiExtWin.CryptGetHashParam(hHash, 2, numArray, ref num, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            return(numArray);
        }
Ejemplo n.º 6
0
        internal static void HashData(SafeHashHandleCP hHash, byte[] data, int idStart, int cbSize)
        {
            try
            {
                byte[] temp = data;
                Array.Copy(data, idStart, temp, 0, cbSize);

                if (!CApiExtWin.CryptHashData(hHash, temp, (uint)cbSize, 0))
                {
                    throw new CryptographicException(Marshal.GetLastWin32Error());
                }

                temp = null;
            }
            catch (Exception ex)
            {
                throw new Exception("Ошибка в методе HashData. " + ex.Message);
            }
        }
Ejemplo n.º 7
0
 internal static extern bool CryptSignHash([In] SafeHashHandleCP hHash, [In] uint dwKeySpec, StringBuilder sDescription,
                                           [In] uint dwFlags, [In][Out] byte[] pbSignature, ref uint pdwSigLen);
Ejemplo n.º 8
0
 internal static extern bool CryptCreateHash([In] SafeProvHandleCP hProv, [In] uint Algid, [In] SafeKeyHandleCP hKey, [In] uint dwFlags, [In][Out] ref SafeHashHandleCP phHash);
Ejemplo n.º 9
0
 internal static extern bool CryptHashData([In] SafeHashHandleCP hHash, byte[] pbData, [In] uint dwDataLen, [In] uint dwFlags);
Ejemplo n.º 10
0
 internal static extern bool CryptGetHashParam([In] SafeHashHandleCP hHash, [In] uint dwParam, [In][Out] byte[] pbData, ref uint pdwDataLen, [In] uint dwFlags);