public static byte[] digest(DigestAlgorithm digestAlgorithm, DSSDocument document) { try (InputStream is = document.openStream()) { return digest(digestAlgorithm, is); } catch (IOException e) { throw new DSSException(e); } }
/** * This method returns true if the inputStream starts with an ASN.1 Sequence * * @param is * the inputstream to be tested * @return true if DER encoded */ public static boolean isStartWithASN1SequenceTag(InputStream is) { byte firstByte = readFirstByte(new InMemoryDocument(is)); return DSSASN1Utils.isASN1SequenceTag(firstByte); }
/** * This method returns the {@link org.w3c.dom.Document} created based on the {@link eu.europa.esig.dss.DSSDocument}. * * @param dssDocument * The DSS representation of the document from which the dssDocument is created. * @return a new {@link org.w3c.dom.Document} from {@link eu.europa.esig.dss.DSSDocument} */ public static Document buildDOM(final DSSDocument dssDocument) { return buildDOM(dssDocument.openStream()); }
/** * Get the contents of an {@code DSSDocument} as a {@code byte[]}. * * @param document * the document to read * @return the content as byte array */ public static byte[] toByteArray(final DSSDocument document) { try (InputStream is = document.openStream()) { return toByteArray(is); } catch (IOException e) { throw new DSSException(e); } }
@Override public InputStream openStream() { throw new DSSException("Digest document"); }
private MessageDigest getMessageDigest(DigestAlgorithm digestAlgorithm) { try { return MessageDigest.getInstance(digestAlgorithm.getOid(), BouncyCastleProvider.PROVIDER_NAME); } catch (GeneralSecurityException e) { throw new DSSException("Cannot generate a MessageDigest", e); } }
public SignatureResponse(SignatureValue signatureValue, CertificateToken certificate, CertificateToken[] certificateChain) { this.signatureValue = signatureValue.getValue(); this.signatureAlgorithm = signatureValue.getAlgorithm(); this.certificate = certificate; this.certificateChain = certificateChain; }
/** * Returns the file media type. * * @return media type */ public String getMediaType() { logger.debug(""); String mediaType = document.getMimeType().getMimeTypeString(); logger.debug("Media type is: " + mediaType); return mediaType; }
/** * This method returns BER encoded ASN1 attribute. The {@code IOException} is * transformed in {@code DSSException}. * * @param asn1Encodable * asn1Encodable to be BER encoded * @return array of bytes representing the BER encoded asn1Encodable */ public static byte[] getBEREncoded(ASN1Encodable asn1Encodable) { return getEncoded(asn1Encodable, ASN1Encoding.BER); }
/** * Creates dss document that retains the data in memory * * @param inputStream * input stream representing the document */ public InMemoryDocument(final InputStream inputStream) { this(DSSUtils.toByteArray(inputStream), null, null); }
/** * This method returns SKI bytes from the certificate extension. * * @param certificateToken * the {@code CertificateToken} * @return ski bytes from the given certificate or null if missing */ public static byte[] getSki(final CertificateToken certificateToken) { return getSki(certificateToken, false); }
/** * Returns the Element corresponding to the XPath query. * * @param xmlNode * The node where the search should be performed. * @param xPathString * XPath query string * @return the Element corresponding to the XPath query */ public static Element getElement(final Node xmlNode, final String xPathString) { return (Element) getNode(xmlNode, xPathString); }
/** * This method returns the {@code ASN1Sequence} encapsulated in * {@code DEROctetString}. The {@code DEROctetString} is represented as * {@code byte} array. * * @param bytes * {@code byte} representation of {@code DEROctetString} * @return encapsulated {@code ASN1Sequence} @ in case of a decoding problem */ public static ASN1Sequence getAsn1SequenceFromDerOctetString(byte[] bytes) { return getASN1Sequence(getDEROctetStringContent(bytes)); }
/** * Gives back the CA URIs meta-data found within the given certificate. * * @param certificate * the certificate token. * @return a list of CA URIs, or empty list if the extension is not present. */ public static List<String> getCAAccessLocations(final CertificateToken certificate) { return getAccessLocations(certificate, X509ObjectIdentifiers.id_ad_caIssuers); }
/** * This method registers the default namespaces. */ private static void registerDefaultNamespaces() { registerNamespace("ds", XMLSignature.XMLNS); registerNamespace("dsig", XMLSignature.XMLNS); registerNamespace("xades", XAdESNamespaces.XAdES); // 1.3.2 registerNamespace("xades141", XAdESNamespaces.XAdES141); registerNamespace("xades122", XAdESNamespaces.XAdES122); registerNamespace("xades111", XAdESNamespaces.XAdES111); }
@Override public void save(String filePath) throws IOException { throw new DSSException("Digest document"); }
/** * This method returns DER encoded ASN1 attribute. The {@code IOException} is * transformed in {@code DSSException}. * * @param asn1Encodable * asn1Encodable to be DER encoded * @return array of bytes representing the DER encoded asn1Encodable */ public static byte[] getDEREncoded(ASN1Encodable asn1Encodable) { return getEncoded(asn1Encodable, ASN1Encoding.DER); }
/** * Creates dss document that retains the data in memory * * @param inputStream * input stream representing the document * @param name * the file name if the data originates from a file */ public InMemoryDocument(final InputStream inputStream, final String name) { this(DSSUtils.toByteArray(inputStream), name); }
/** * Gives back the OCSP URIs meta-data found within the given X509 cert. * * @param certificate * the cert token. * @return a list of OCSP URIs, or empty list if the extension is not present. */ public static List<String> getOCSPAccessLocations(final CertificateToken certificate) { return getAccessLocations(certificate, X509ObjectIdentifiers.id_ad_ocsp); }
@Override public void setContentType(String contentType) { throw new DSSException("Not implemented"); }