public eu.europa.esig.dss.DigestAlgorithm getDssDigestAlgorithm() { return eu.europa.esig.dss.DigestAlgorithm.forXML(uri.toString()); }
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { if ("ds:SignedInfo".equals(qName)) { signedInfo = true; } if (signedInfo && "ds:Reference".equals(qName)) { reference = true; currentDatafile = new Datafile(); for (int i = 0; i < attributes.getLength(); i++) { if ("URI".equals(attributes.getQName(i))) { try { currentDatafile.setFilename(URLDecoder.decode(attributes.getValue(i), "UTF-8")); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException("Invalid file name"); } } } } if (signedInfo && reference && "ds:DigestMethod".equals(qName)) { for (int i = 0; i < attributes.getLength(); i++) { if ("Algorithm".equals(attributes.getQName(i))) { currentDatafile.setHashAlgo(DigestAlgorithm.forXML(attributes.getValue(i)).getName()); } } } }
/** * Calculates digest for data file. If digest is already calculated returns it, otherwise calculates the digest. * <p>Supported uris for BDoc:</p> * <br>http://www.w3.org/2000/09/xmldsig#sha1 * <br>http://www.w3.org/2001/04/xmldsig-more#sha224 * <br>http://www.w3.org/2001/04/xmlenc#sha256 * <br>http://www.w3.org/2001/04/xmldsig-more#sha384 * <br>http://www.w3.org/2001/04/xmlenc#sha512 * <p>In case of DDoc files the parameter is ignored and SHA1 hash is always returned</p> * * @param method method uri for calculating the digest * @return calculated digest */ public byte[] calculateDigest(URL method) { // TODO exceptions to throw logger.debug("URL method: " + method); if (digest == null) { DigestAlgorithm digestAlgorithm = DigestAlgorithm.forXML(method.toString()); digest = new Digest(digestAlgorithm, calculateDigestInternal(digestAlgorithm)); } else { logger.debug("Returning existing digest value"); } return digest.getValue(); }
public SignedInfo(byte[] dataToDigest, SignatureParameters signatureParameters) { DigestAlgorithm digestAlgorithm = signatureParameters.getDigestAlgorithm(); digestToSign = DSSUtils.digest(forXML(digestAlgorithm.toString()), dataToDigest); this.signatureParameters = signatureParameters; }
private byte[] signECDSA(DigestAlgorithm digestAlgorithm, byte[] dataToSign) { try { logger.debug("Signing with PKCS#11 and " + digestAlgorithm.name()); ToBeSigned toBeSigned = new ToBeSigned(dataToSign); eu.europa.esig.dss.DigestAlgorithm dssDigestAlgorithm = eu.europa.esig.dss.DigestAlgorithm.forXML(digestAlgorithm.toString()); SignatureValue signature = signatureTokenConnection.sign(toBeSigned, dssDigestAlgorithm, privateKeyEntry); return signature.getValue(); } catch (Exception e) { logger.error("Failed to sign with PKCS#11: " + e.getMessage()); throw new TechnicalException("Failed to sign with PKCS#11: " + e.getMessage(), e); } /* */ }
@Override public byte[] sign(org.digidoc4j.DigestAlgorithm digestAlgorithm, byte[] dataToSign) { logger.info("Signing with PKCS#12 signature token, using digest algorithm: " + digestAlgorithm.name()); ToBeSigned toBeSigned = new ToBeSigned(dataToSign); eu.europa.esig.dss.DigestAlgorithm dssDigestAlgorithm = eu.europa.esig.dss.DigestAlgorithm.forXML(digestAlgorithm.toString()); SignatureValue signature = signatureTokenConnection.sign(toBeSigned, dssDigestAlgorithm, keyEntry); return signature.getValue(); }