Ejemplo n.º 1
0
        public void Sign(byte[] certificate, Payment.PKIType type)
        {
            if (type == Payment.PKIType.None)
            {
                throw new ArgumentException("PKIType can't be none if signing");
            }
            var signer = GetCertificateProvider().GetSigner();

            MerchantCertificate = signer.StripPrivateKey(certificate);
            PKIType             = type;
            var data = GetSignedData();

            byte[] hash     = null;
            string hashName = null;

            if (type == Payment.PKIType.X509SHA256)
            {
                hash     = Hashes.SHA256(data);
                hashName = "sha256";
            }
            else if (type == Payment.PKIType.X509SHA1)
            {
                hash     = Hashes.SHA1(data, 0, data.Length);
                hashName = "sha1";
            }
            else
            {
                throw new NotSupportedException(PKIType.ToString());
            }

            Signature = signer.Sign(certificate, hash, hashName);
        }
Ejemplo n.º 2
0
        public void Sign(X509Certificate2 certificate, Payment.PKIType type)
        {
            if (type == Payment.PKIType.None)
            {
                throw new ArgumentException("PKIType can't be none if signing");
            }
            var privateKey = certificate.PrivateKey as RSACryptoServiceProvider;

            if (privateKey == null)
            {
                throw new ArgumentException("Private key not present in the certificate, impossible to sign");
            }
            MerchantCertificate = new X509Certificate2(certificate.Export(X509ContentType.Cert));
            PKIType             = type;
            Signature           = new byte[0];
            var data = this.ToBytes();

            byte[] hash     = null;
            string hashName = null;

            if (type == Payment.PKIType.X509SHA256)
            {
                hash     = Hashes.SHA256(data);
                hashName = "sha256";
            }
            else if (type == Payment.PKIType.X509SHA1)
            {
                hash     = Hashes.SHA1(data, data.Length);
                hashName = "sha1";
            }
            else
            {
                throw new NotSupportedException(PKIType.ToString());
            }

            Signature = privateKey.SignHash(hash, hashName);
        }
Ejemplo n.º 3
0
 public void Sign(byte[] certificate, Payment.PKIType type)
 {
     Sign((object)certificate, type);
 }
Ejemplo n.º 4
0
 public void Sign(X509Certificate2 certificate, Payment.PKIType type)
 {
     Sign((object)certificate, type);
 }