Exemplo n.º 1
0
        public static void Smartcardsign(Session session, String alias)
        {
            // Searchs for an RSA certificate object
            // Sets the template with its attributes
            CryptokiCollection template = new CryptokiCollection();

            template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_CERTIFICATE));
            template.Add(new ObjectAttribute(ObjectAttribute.CKA_CERTIFICATE_TYPE, Certificate.CKC_X_509));
            template.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, alias));

            Cryptware.NCryptoki.X509Certificate nCert = (Cryptware.NCryptoki.X509Certificate)session.Objects.Find(template);

            X509Certificate2 cert = Utils.ConvertCertificate(nCert);
            ICollection <X509Certificate> chain = new List <X509Certificate>();
            X509Chain x509chain = new X509Chain();

            x509chain.Build(cert);

            foreach (X509ChainElement x509ChainElement in x509chain.ChainElements)
            {
                chain.Add(DotNetUtilities.FromX509Certificate(x509ChainElement.Certificate));
            }

            IOcspClient       ocspClient = new OcspClientBouncyCastle();
            List <ICrlClient> crlList    = new List <ICrlClient>();

            crlList.Add(new CrlClientOnline(chain));
            C4_03_SignWithPKCS11SC app = new C4_03_SignWithPKCS11SC();

            app.Sign(SRC, String.Format(DEST, alias), chain, session, alias, DigestAlgorithms.SHA256, CryptoStandard.CMS,
                     "Test", "Ghent", crlList, ocspClient, null, 0);
        }
Exemplo n.º 2
0
        public CryptokiPrivateKeySignature(Session session, String alias)
        {
            this.session = session;
            CryptokiCollection template = new CryptokiCollection();

            template.Add(new ObjectAttribute(ObjectAttribute.CKA_CLASS, CryptokiObject.CKO_PRIVATE_KEY));
            template.Add(new ObjectAttribute(ObjectAttribute.CKA_KEY_TYPE, Key.CKK_RSA));
            template.Add(new ObjectAttribute(ObjectAttribute.CKA_LABEL, alias));
            privateKey = (RSAPrivateKey)session.Objects.Find(template);
        }