Example #1
0
 internal static extern ErrorCode NCryptVerifySignature(SafeNCryptKeyHandle hKey,
                                                        [In] ref BCryptNative.BCRYPT_PKCS1_PADDING_INFO pPaddingInfo,
                                                        [In, MarshalAs(UnmanagedType.LPArray)] byte[] pbHashValue,
                                                        int cbHashValue,
                                                        [In, MarshalAs(UnmanagedType.LPArray)] byte[] pbSignature,
                                                        int cbSignature,
                                                        AsymmetricPaddingMode dwFlags);
Example #2
0
 internal static extern ErrorCode NCryptEncrypt(SafeNCryptKeyHandle hKey,
                                                [In, MarshalAs(UnmanagedType.LPArray)] byte[] pbInput,
                                                int cbInput,
                                                [In] ref BCryptNative.BCRYPT_PKCS1_PADDING_INFO pvPadding,
                                                [Out, MarshalAs(UnmanagedType.LPArray)] byte[] pbOutput,
                                                int cbOutput,
                                                [Out] out int pcbResult,
                                                AsymmetricPaddingMode dwFlags);
Example #3
0
        internal static byte[] EncryptDataPkcs1(SafeNCryptKeyHandle key, byte[] data)
        {
            BCryptNative.BCRYPT_PKCS1_PADDING_INFO pkcs1Info = new BCryptNative.BCRYPT_PKCS1_PADDING_INFO();

            return(EncryptData(key,
                               data,
                               ref pkcs1Info,
                               AsymmetricPaddingMode.Pkcs1,
                               UnsafeNativeMethods.NCryptEncrypt));
        }
Example #4
0
        public static byte[] SignHashPkcs1(SafeNCryptKeyHandle key,
                                           byte[] hash,
                                           string hashAlgorithm)
        {
            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)");

            BCryptNative.BCRYPT_PKCS1_PADDING_INFO pkcs1Info = new BCryptNative.BCRYPT_PKCS1_PADDING_INFO();
            pkcs1Info.pszAlgId = hashAlgorithm;

            return(SignHash(key,
                            hash,
                            ref pkcs1Info,
                            AsymmetricPaddingMode.Pkcs1,
                            UnsafeNativeMethods.NCryptSignHash));
        }
Example #5
0
        internal static bool VerifySignaturePkcs1(SafeNCryptKeyHandle key,
                                                  byte[] hash,
                                                  string hashAlgorithm,
                                                  byte[] signature)
        {
            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(signature != null, "signature != null");

            BCryptNative.BCRYPT_PKCS1_PADDING_INFO pkcs1Info = new BCryptNative.BCRYPT_PKCS1_PADDING_INFO();
            pkcs1Info.pszAlgId = hashAlgorithm;

            return(VerifySignature(key,
                                   hash,
                                   signature,
                                   ref pkcs1Info,
                                   AsymmetricPaddingMode.Pkcs1,
                                   UnsafeNativeMethods.NCryptVerifySignature));
        }