internal static void VerifyStatus(CngNative.ErrorCode status)
 {
     if (status != CngNative.ErrorCode.Success)
     {
         throw new Win32Exception((int)status);
     }
 }
        internal static int NCryptGetPropertyInt32(SafeCryptKeyHandle hObject, string propertyName)
        {
            byte[] array = new byte[4];
            int    num;

            CngNative.ErrorCode errorCode = CngNative.NCryptGetProperty(hObject, propertyName, array, array.Length, out num, 0);
            if (errorCode != CngNative.ErrorCode.Success)
            {
                throw new Win32Exception((int)errorCode);
            }
            return(BitConverter.ToInt32(array, 0));
        }
        public override byte[] Sign(byte[] data, SignatureHashAlgorithm hashAlgorithm)
        {
            HashAlgorithm hashAlgorithm2 = hashAlgorithm.CreateAlgorithm();

            byte[] array = hashAlgorithm2.ComputeHash(data);
            int    num;

            CngNative.ErrorCode status = CngNative.NCryptSignHash(base.KeyHandle, IntPtr.Zero, array, array.Length, null, 0, out num, 0);
            CngNative.VerifyStatus(status);
            byte[] array2 = new byte[num];
            status = CngNative.NCryptSignHash(base.KeyHandle, IntPtr.Zero, array, array.Length, array2, array2.Length, out num, 0);
            CngNative.VerifyStatus(status);
            return(array2);
        }
        public override byte[] Sign(byte[] data, SignatureHashAlgorithm hashAlgorithm)
        {
            HashAlgorithm hashAlgorithm2 = hashAlgorithm.CreateAlgorithm();

            byte[] array = hashAlgorithm2.ComputeHash(data);
            CngNative.BCRYPT_PKCS1_PADDING_INFO bCRYPT_PKCS1_PADDING_INFO = default(CngNative.BCRYPT_PKCS1_PADDING_INFO);
            bCRYPT_PKCS1_PADDING_INFO.pszAlgId = hashAlgorithm.Name;
            int num;

            CngNative.ErrorCode status = CngNative.NCryptSignHashPkcs1(base.KeyHandle, ref bCRYPT_PKCS1_PADDING_INFO, array, array.Length, null, 0, out num, CngNative.AsymmetricPaddingMode.Pkcs1);
            CngNative.VerifyStatus(status);
            byte[] array2 = new byte[num];
            status = CngNative.NCryptSignHashPkcs1(base.KeyHandle, ref bCRYPT_PKCS1_PADDING_INFO, array, array.Length, array2, array2.Length, out num, CngNative.AsymmetricPaddingMode.Pkcs1);
            CngNative.VerifyStatus(status);
            return(array2);
        }
        internal static string NCryptGetPropertyString(SafeCryptKeyHandle hObject, string propertyName)
        {
            int num = 0;

            CngNative.ErrorCode errorCode = CngNative.NCryptGetProperty(hObject, propertyName, null, 0, out num, 0);
            if (errorCode != CngNative.ErrorCode.Success)
            {
                throw new Win32Exception((int)errorCode);
            }
            byte[] array = new byte[num];
            errorCode = CngNative.NCryptGetProperty(hObject, propertyName, array, array.Length, out num, 0);
            if (errorCode != CngNative.ErrorCode.Success)
            {
                throw new Win32Exception((int)errorCode);
            }
            string arg_4E_0 = Encoding.Unicode.GetString(array, 0, num);

            char[] trimChars = new char[1];
            return(arg_4E_0.Trim(trimChars));
        }