예제 #1
0
        internal static byte[] GetHashParameter(SafeCapiHashHandle hashHandle, HashParameter parameter)
        {
            int pdwDataLen = 0;

            if (!UnsafeNativeMethods.CryptGetHashParam(hashHandle, parameter, null, ref pdwDataLen, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            byte[] pbData = new byte[pdwDataLen];
            if (!UnsafeNativeMethods.CryptGetHashParam(hashHandle, parameter, pbData, ref pdwDataLen, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }
            if (pdwDataLen != pbData.Length)
            {
                byte[] dst = new byte[pdwDataLen];
                Buffer.BlockCopy(pbData, 0, dst, 0, pdwDataLen);
                pbData = dst;
            }
            return(pbData);
        }
예제 #2
0
 public static extern bool CryptGetHashParam(SafeCapiHashHandle hHash,
                                             HashParameter dwParam,
                                             [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbData,
                                             [In, Out] ref int pdwDataLen,
                                             int dwFlags);
 internal static extern bool CryptSetHashParam(
     SafeCryptoHashHandle hash,
     HashParameter paramter,
     [In, Out] ref HMAC_INFO hmacInfo,
     uint flags
 );
        /// <summary>
        /// Gets the hash parameter.  This method wraps the underlying
        /// api to obtain the length of the result and appropriately
        /// size a result byte buffer.
        /// </summary>
        /// 
        /// <param name="hashHandle">
        /// The hash handle.
        /// </param>
        /// 
        /// <param name="hashParameter">
        /// The hash parameter.
        /// </param>
        /// 
        /// <returns>
        /// <c>true</c> if successful, otherwise <c>false</c>.
        /// </returns>
        internal static byte[] GetHashParameterWrapper(
            SafeCryptoHashHandle hashHandle,
            HashParameter hashParameter)
        {
            int hashLength = 0;
            if (!UnsafeNativeMethods.CryptGetHashParam(
                hashHandle, hashParameter, null, ref hashLength, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            byte[] hash = new byte[hashLength];
            if (!UnsafeNativeMethods.CryptGetHashParam(
                hashHandle, hashParameter, hash, ref hashLength, 0))
            {
                throw new CryptographicException(Marshal.GetLastWin32Error());
            }

            return hash;
        }
 internal static extern bool CryptGetHashParam(
     SafeCryptoHashHandle hash,
     HashParameter hashParameter,
     [Out, MarshalAs(UnmanagedType.LPArray)] byte[] hashValue,
     [In, Out] ref int length,
     int flags);