示例#1
0
 internal static void SetHashProperty(SafeCspHashHandle hashHandle, CapiNative.HashProperty property, byte[] value)
 {
     if (!CapiNative.UnsafeNativeMethods.CryptSetHashParam(hashHandle, property, value, 0))
     {
         throw new CryptographicException(Marshal.GetLastWin32Error());
     }
 }
示例#2
0
 internal static int GetHashPropertyInt32(SafeCspHashHandle hashHandle, CapiNative.HashProperty property)
 {
     byte[] hashProperty = CapiNative.GetHashProperty(hashHandle, property);
     if (hashProperty.Length != 4)
     {
         return(0);
     }
     return(BitConverter.ToInt32(hashProperty, 0));
 }
示例#3
0
        internal static byte[] GetHashProperty(SafeCspHashHandle hashHandle, CapiNative.HashProperty property)
        {
            int pdwDataLen = 0;

            byte[] pbData1 = (byte[])null;
            if (!CapiNative.UnsafeNativeMethods.CryptGetHashParam(hashHandle, property, pbData1, out pdwDataLen, 0))
            {
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (lastWin32Error != 234)
                {
                    throw new CryptographicException(lastWin32Error);
                }
            }
            byte[] pbData2 = new byte[pdwDataLen];
            if (!CapiNative.UnsafeNativeMethods.CryptGetHashParam(hashHandle, property, pbData2, out pdwDataLen, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            return(pbData2);
        }
        internal static byte[] GetHashProperty(SafeCspHashHandle hashHandle, CapiNative.HashProperty property)
        {
            int num = 0;

            byte[] array = null;
            if (!CapiNative.UnsafeNativeMethods.CryptGetHashParam(hashHandle, property, array, ref num, 0))
            {
                int lastWin32Error = Marshal.GetLastWin32Error();
                if (lastWin32Error != 234)
                {
                    throw new CryptographicException(lastWin32Error);
                }
            }
            array = new byte[num];
            if (!CapiNative.UnsafeNativeMethods.CryptGetHashParam(hashHandle, property, array, ref num, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            return(array);
        }
示例#5
0
 internal static extern bool CryptSetHashParam(SafeCspHashHandle hHash, CapiNative.HashProperty dwParam, [MarshalAs(UnmanagedType.LPArray), In] byte[] pbData, int dwFlags);
 internal static extern bool CryptGetHashParam(SafeCspHashHandle hHash, CapiNative.HashProperty dwParam, [MarshalAs(UnmanagedType.LPArray)][In][Out] byte[] pbData, [In][Out] ref int pdwDataLen, int dwFlags);