Beispiel #1
0
        virtual protected void SignPackageWithKeyInfo(String src, String dest, XfaXpathConstructor.XdpPackage xdpPackage,
                                                      ICipherParameters pk, AsymmetricAlgorithm publicKey, String digestAlgorithm)
        {
            // Creating the reader and the stamper
            PdfReader  reader  = new PdfReader(src);
            FileStream os      = new FileStream(dest, FileMode.Create);
            PdfStamper stamper = PdfStamper.createXmlSignature(reader, os);
            // Creating the appearance
            XmlSignatureAppearance appearance = stamper.XmlSignatureAppearance;

            //Set XfaXmlLocator to control getting and setting Document
            appearance.SetXmlLocator(new XfaXmlLocator(stamper));
            // Set XpathConstructor, to construct xpath expression for signing an xdp package
            appearance.SetXpathConstructor(new XfaXpathConstructor(xdpPackage));
            // Creating the signature
            IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm);

            KeyInfoClause keyInfo;

            if (publicKey is DSA)
            {
                keyInfo = new DSAKeyValue((DSA)publicKey);
            }
            else if (publicKey is RSA)
            {
                keyInfo = new RSAKeyValue((RSA)publicKey);
            }
            else
            {
                throw new ArgumentException("Invalid public key algorithm", "publicKey");
            }

            MakeXmlSignature.SignXmlDSig(appearance, pks, keyInfo);
        }
Beispiel #2
0
        virtual protected void SignPackageWithPublicKey(String src, String dest, XfaXpathConstructor.XdpPackage xdpPackage,
                                                        ICipherParameters pk, AsymmetricAlgorithm publicKey, String digestAlgorithm)
        {
            // Creating the reader and the stamper
            PdfReader  reader  = new PdfReader(src);
            FileStream os      = new FileStream(dest, FileMode.Create);
            PdfStamper stamper = PdfStamper.createXmlSignature(reader, os);
            // Creating the appearance
            XmlSignatureAppearance appearance = stamper.XmlSignatureAppearance;

            //Set XfaXmlLocator to control getting and setting Document
            appearance.SetXmlLocator(new XfaXmlLocator(stamper));
            // Set XpathConstructor, to construct xpath expression for signing an xdp package
            appearance.SetXpathConstructor(new XfaXpathConstructor(xdpPackage));
            // Creating the signature
            IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm);

            MakeXmlSignature.SignXmlDSig(appearance, pks, publicKey);
        }
Beispiel #3
0
        virtual protected void SignXadesPackage(String src, String dest, XfaXpathConstructor.XdpPackage xdpPackage,
                                                ICipherParameters pk, X509Certificate[] chain, String digestAlgorithm, bool includeSignaturePolicy)
        {
            // Creating the reader and the stamper
            PdfReader  reader  = new PdfReader(src);
            FileStream os      = new FileStream(dest, FileMode.Create);
            PdfStamper stamper = PdfStamper.createXmlSignature(reader, os);
            // Creating the appearance
            XmlSignatureAppearance appearance = stamper.XmlSignatureAppearance;

            //Set XfaXmlLocator to control getting and setting Document
            appearance.SetXmlLocator(new XfaXmlLocator(stamper));
            appearance.SetDescription("Simple xfa form");
            // Set XpathConstructor, to construct xpath expression for signing an xdp package
            appearance.SetXpathConstructor(new XfaXpathConstructor(xdpPackage));
            // Creating the signature
            IExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm);

            MakeXmlSignature.SignXades(appearance, pks, chain, includeSignaturePolicy);
        }