Exemplo n.º 1
0
 internal static extern ErrorCode NCryptSignHash(SafeNCryptKeyHandle hKey,
                                                 [In] ref BCryptNative.BCRYPT_PSS_PADDING_INFO pPaddingInfo,
                                                 [In, MarshalAs(UnmanagedType.LPArray)] byte[] pbHashValue,
                                                 int cbHashValue,
                                                 [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbSignature,
                                                 int cbSignature,
                                                 [Out] out int pcbResult,
                                                 AsymmetricPaddingMode dwFlags);
Exemplo n.º 2
0
        internal static byte[] SignHashPss(SafeNCryptKeyHandle key,
                                           byte[] hash,
                                           string hashAlgorithm,
                                           int saltBytes)
        {
            Debug.Assert(key != null, "key != null");
            Debug.Assert(!key.IsClosed && !key.IsInvalid, "!key.IsClosed && !key.IsInvalid");
            Debug.Assert(hash != null, "hash != null");
            Debug.Assert(!String.IsNullOrEmpty(hashAlgorithm), "!String.IsNullOrEmpty(hashAlgorithm)");
            Debug.Assert(saltBytes >= 0, "saltBytes >= 0");

            BCryptNative.BCRYPT_PSS_PADDING_INFO pssInfo = new BCryptNative.BCRYPT_PSS_PADDING_INFO();
            pssInfo.pszAlgId = hashAlgorithm;
            pssInfo.cbSalt   = saltBytes;

            return(SignHash(key,
                            hash,
                            ref pssInfo,
                            AsymmetricPaddingMode.Pss,
                            UnsafeNativeMethods.NCryptSignHash));
        }