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);
        }
Example #3
0
 public abstract byte[] Sign(byte[] data, SignatureHashAlgorithm hashAlgorithm);
 public TokenSigner(SigningKey key, SignatureHashAlgorithm hashAlgorithm)
 {
     this.m_key           = key;
     this.m_hashAlgorithm = hashAlgorithm;
 }
 public TokenSigner(X509Certificate2 certificate, SignatureHashAlgorithm hashAlgorithm) : this(SigningKey.CreateFromCertificate(certificate), hashAlgorithm)
 {
 }