For IntelliJ IDEA,
Android Studio or Eclipse



private void incorporateSigningCertificateV1(Set<CertificateToken> certificates) { Element signingCertificateDom = DomUtils.addElement(documentDom, signedSignaturePropertiesDom, XAdES, XAdESNamespaces.getXADES_SIGNING_CERTIFICATE()); for (final CertificateToken certificate : certificates) { final Element certDom = incorporateCert(signingCertificateDom, certificate); incorporateIssuerV1(certDom, certificate); } }
protected void incorporateIssuerV2(final Element parentDom, final CertificateToken certificate) { final Element issuerSerialDom = DomUtils.addElement(documentDom, parentDom, XAdES, XADES_ISSUER_SERIAL_V2); IssuerSerial issuerSerial = DSSASN1Utils.getIssuerSerial(certificate); String issuerBase64 = Utils.toBase64(DSSASN1Utils.getDEREncoded(issuerSerial)); DomUtils.setTextNode(documentDom, issuerSerialDom, issuerBase64); }
private void incorporateOcspTokens(Element parentDom, final List<OCSPToken> ocspTokens) { if (ocspTokens.isEmpty()) { return; } // ...<xades:OCSPValues> // .........<xades:EncapsulatedOCSPValue>MIIERw... final Element ocspValuesDom = DomUtils.addElement(documentDom, parentDom, XAdESNamespaces.XAdES, "xades:OCSPValues"); for (final RevocationToken revocationToken : ocspTokens) { final byte[] encodedOCSP = revocationToken.getEncoded(); final String base64EncodedOCSP = Utils.toBase64(encodedOCSP); DomUtils.addTextElement(documentDom, ocspValuesDom, XAdESNamespaces.XAdES, "xades:EncapsulatedOCSPValue", base64EncodedOCSP); } }
public void incorporateSignedInfo() { // <ds:SignedInfo> signedInfoDom = DomUtils.addElement(documentDom, signatureDom, XMLNS, DS_SIGNED_INFO); incorporateCanonicalizationMethod(signedInfoDom, signedInfoCanonicalizationMethod); // <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/> final Element signatureMethod = DomUtils.addElement(documentDom, signedInfoDom, XMLNS, DS_SIGNATURE_METHOD); final EncryptionAlgorithm encryptionAlgorithm = params.getEncryptionAlgorithm(); final DigestAlgorithm digestAlgorithm = params.getDigestAlgorithm(); final MaskGenerationFunction mgf = params.getMaskGenerationFunction(); final SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.getAlgorithm(encryptionAlgorithm, digestAlgorithm, mgf); final String signatureAlgorithmXMLId = signatureAlgorithm.getXMLId(); signatureMethod.setAttribute(ALGORITHM, signatureAlgorithmXMLId); }
protected void addSigReference(final Document documentDom, final Element asicManifestDom, String uri, MimeType mimeType) { final Element sigReferenceDom = DomUtils.addElement(documentDom, asicManifestDom, ASiCNamespace.NS, ASiCNamespace.SIG_REFERENCE); sigReferenceDom.setAttribute("URI", uri); sigReferenceDom.setAttribute("MimeType", mimeType.getMimeTypeString()); }
/** * Creates the SignedProperties DOM object element. * * @throws DSSException */ protected void incorporateSignedProperties() throws DSSException { // <SignedProperties Id="xades-ide5c549340079fe19f3f90f03354a5965"> signedPropertiesDom = DomUtils.addElement(documentDom, qualifyingPropertiesDom, XAdES, XADES_SIGNED_PROPERTIES); signedPropertiesDom.setAttribute(ID, "xades-" + deterministicId); incorporateSignedSignatureProperties(); }
private void incorporateCrlTokens(final Element parentDom, final List<CRLToken> crlTokens) { if (crlTokens.isEmpty()) { return; } // ...<xades:CRLValues/> final Element crlValuesDom = DomUtils.addElement(documentDom, parentDom, XAdESNamespaces.XAdES, "xades:CRLValues"); for (final RevocationToken revocationToken : crlTokens) { final byte[] encodedCRL = revocationToken.getEncoded(); final String base64EncodedCRL = Utils.toBase64(encodedCRL); DomUtils.addTextElement(documentDom, crlValuesDom, XAdESNamespaces.XAdES, "xades:EncapsulatedCRLValue", base64EncodedCRL); } }
private void addRoles(final List<String> signerRoles, final Element rolesDom, final String roleType) { for (final String signerRole : signerRoles) { final Element roleDom = DomUtils.addElement(documentDom, rolesDom, XAdES, roleType); DomUtils.setTextNode(documentDom, roleDom, signerRole); } }
protected void incorporateIssuerV1(final Element parentDom, final CertificateToken certificate) { final Element issuerSerialDom = DomUtils.addElement(documentDom, parentDom, XAdES, XADES_ISSUER_SERIAL); final Element x509IssuerNameDom = DomUtils.addElement(documentDom, issuerSerialDom, XMLNS, DS_X509_ISSUER_NAME); final String issuerX500PrincipalName = certificate.getIssuerX500Principal().getName(); DomUtils.setTextNode(documentDom, x509IssuerNameDom, issuerX500PrincipalName); final Element x509SerialNumberDom = DomUtils.addElement(documentDom, issuerSerialDom, XMLNS, DS_X509_SERIAL_NUMBER); final BigInteger serialNumber = certificate.getSerialNumber(); final String serialNumberString = new String(serialNumber.toString()); DomUtils.setTextNode(documentDom, x509SerialNumberDom, serialNumberString); }
private void incorporateSigningCertificateV2(Set<CertificateToken> certificates) { Element signingCertificateDom = DomUtils.addElement(documentDom, signedSignaturePropertiesDom, XAdES, XAdESNamespaces.getXADES_SIGNING_CERTIFICATE_V2()); for (final CertificateToken certificate : certificates) { final Element certDom = incorporateCert(signingCertificateDom, certificate); incorporateIssuerV2(certDom, certificate); } }
protected Element incorporateCert(final Element parentDom, final CertificateToken certificate) { final Element certDom = DomUtils.addElement(documentDom, parentDom, XAdES, XADES_CERT); final Element certDigestDom = DomUtils.addElement(documentDom, certDom, XAdES, XADES_CERT_DIGEST); final DigestAlgorithm signingCertificateDigestMethod = params.getSigningCertificateDigestMethod(); incorporateDigestMethod(certDigestDom, signingCertificateDigestMethod); incorporateDigestValue(certDigestDom, signingCertificateDigestMethod, certificate); return certDom; }
/** * @throws DSSException */ protected void incorporateObject() throws DSSException { // <ds:Object> final Element objectDom = DomUtils.addElement(documentDom, signatureDom, XMLNS, DS_OBJECT); // <QualifyingProperties xmlns="http://uri.etsi.org/01903/v1.3.2#" // Target="#sigId-ide5c549340079fe19f3f90f03354a5965"> qualifyingPropertiesDom = DomUtils.addElement(documentDom, objectDom, XAdES, XADES_QUALIFYING_PROPERTIES); qualifyingPropertiesDom.setAttribute(XMLNS_XADES, XAdES); qualifyingPropertiesDom.setAttribute(TARGET, "#" + deterministicId); incorporateSignedProperties(); }
private void incorporateCanonicalizationMethod(final Element parentDom, final String signedInfoCanonicalizationMethod) { // <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> final Element canonicalizationMethodDom = DomUtils.addElement(documentDom, parentDom, XMLNS, DS_CANONICALIZATION_METHOD); canonicalizationMethodDom.setAttribute(ALGORITHM, signedInfoCanonicalizationMethod); }
/** * This method incorporates the signature value. */ protected void incorporateSignatureValue() { signatureValueDom = DomUtils.addElement(documentDom, signatureDom, XMLNS, DS_SIGNATURE_VALUE); signatureValueDom.setAttribute(ID, "value-" + deterministicId); }
private void incorporateCrlTokens(final Element parentDom, final List<CRLToken> crlTokens) { if (crlTokens.isEmpty()) { return; } // ...<xades:CRLValues/> final Element crlValuesDom = DomUtils.addElement(documentDom, parentDom, XAdESNamespaces.XAdES, "xades:CRLValues"); for (final RevocationToken revocationToken : crlTokens) { final byte[] encodedCRL = revocationToken.getEncoded(); final String base64EncodedCRL = Utils.toBase64(encodedCRL); DomUtils.addTextElement(documentDom, crlValuesDom, XAdESNamespaces.XAdES, "xades:EncapsulatedCRLValue", base64EncodedCRL); } }