public final class DSSUtils extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DATE_FORMAT
The default date pattern: "yyyy-MM-dd"
|
static String |
DEFAULT_DATE_TIME_FORMAT |
static byte[] |
EMPTY_BYTE_ARRAY |
| Modifier and Type | Method and Description |
|---|---|
static int |
available(InputStream is)
Returns an estimate of the number of bytes that can be read (or
skipped over) from this input stream without blocking by the next
invocation of a method for this input stream.
|
static byte[] |
concatenate(byte[]... arrays)
Concatenates all the arrays into a new array.
|
static byte[] |
convertToDER(String pemContent)
This method converts a PEM encoded certificate/crl/...
|
static String |
convertToPEM(CertificateToken cert)
This method converts the given certificate into its PEM string.
|
static String |
decodeUrl(String uri) |
static byte[] |
digest(DigestAlgorithm digestAlgorithm,
byte[]... data) |
static byte[] |
digest(DigestAlgorithm digestAlgorithm,
byte[] data)
This method allows to digest the data with the given algorithm.
|
static byte[] |
digest(DigestAlgorithm digestAlgorithm,
DSSDocument document) |
static byte[] |
digest(DigestAlgorithm digestAlgo,
InputStream inputStream)
This method allows to digest the data in the
InputStream with the given algorithm. |
static boolean |
fileExists(String path)
This method checks if the file with the given path exists.
|
static String |
formatInternal(Date date)
Formats a date to use for internal purposes (logging, toString)
|
static long |
getDateDiff(Date date1,
Date date2,
TimeUnit timeUnit)
Gets a difference between two dates
|
static String |
getDeterministicId(Date signingTime,
TokenIdentifier id)
Return a unique id for a date and the certificateToken id.
|
static File |
getFile(String filePath)
This method returns a file reference.
|
static String |
getFinalFileName(DSSDocument originalFile,
SigningOperation operation,
SignatureLevel level) |
static String |
getFinalFileName(DSSDocument originalFile,
SigningOperation operation,
SignatureLevel level,
ASiCContainerType containerType) |
static String |
getMD5Digest(byte[] bytes)
Returns a Hex encoded of the MD5 digest of binaries
|
static MessageDigest |
getMessageDigest(DigestAlgorithm digestAlgorithm)
Returns a new instance of MessageDigest for a given digest algorithm
|
static String |
getMessageId(String message)
This method return the unique message id which can be used for translation purpose.
|
static X500Principal |
getNormalizedX500Principal(X500Principal x500Principal)
This method normalizes the X500Principal object
|
static InputStream |
getResource(String resourcePath) |
static String |
getSHA1Digest(String stringToDigest)
This method digests the given string with SHA1 algorithm and encode returned array of bytes as hex string.
|
static String |
getSummaryMessage(Exception exception,
Class<?> javaClass)
This method returns the summary of the given exception.
|
static Date |
getUtcDate(int year,
int month,
int day)
This method returns an UTC date base on the year, the month and the day.
|
static X500Principal |
getX500PrincipalOrNull(String x500PrincipalString)
This method returns the
X500Principal corresponding to the given string or null if the conversion
is not possible. |
static boolean |
isStartWithASN1SequenceTag(InputStream is)
This method returns true if the inputStream starts with an ASN.1 Sequence
|
static CertificateToken |
loadCertificate(byte[] input)
This method loads a certificate from the byte array.
|
static CertificateToken |
loadCertificate(File file)
This method loads a certificate from the given location.
|
static CertificateToken |
loadCertificate(InputStream inputStream)
This method loads a certificate from the given location.
|
static CertificateToken |
loadCertificate(String path)
This method loads a certificate from the given resource.
|
static CertificateToken |
loadCertificateFromBase64EncodedString(String base64Encoded)
This method loads a certificate from a base 64 encoded String
|
static Collection<CertificateToken> |
loadCertificateFromP7c(InputStream is) |
static Collection<CertificateToken> |
loadPotentialIssuerCertificates(CertificateToken cert,
DataLoader loader)
This method loads the potential issuer certificate(s) from the given locations (AIA).
|
static void |
printSecurityProviders()
This method lists all defined security providers.
|
static byte |
readFirstByte(DSSDocument dssDocument)
Reads the first byte from the DSSDocument
|
static int |
readToArray(DSSDocument dssDocument,
int headerLength,
byte[] destinationByteArray)
Reads maximum
headerLength bytes from dssDocument to the given byte array. |
static boolean |
resourceExists(String path)
This method checks if the resource with the given path exists.
|
static void |
saveToFile(byte[] bytes,
File file)
This method saves the given array of
byte to the provided File. |
static DSSDocument |
splitDocument(DSSDocument origin,
int start,
int end)
This method create a new document from a sub-part of another document
|
static byte[] |
toByteArray(DSSDocument document)
Get the contents of an
DSSDocument as a byte[]. |
static byte[] |
toByteArray(File file)
FROM: Apache
Reads the contents of a file into a byte array.
|
static byte[] |
toByteArray(InputStream inputStream)
Get the contents of an
InputStream as a byte[]. |
static InputStream |
toByteArrayInputStream(File file)
This method returns an
InputStream which does not need to be closed, based on
ByteArrayInputStream. |
protected static int |
toDigit(char ch,
int index)
Converts a hexadecimal character to an integer.
|
static FileOutputStream |
toFileOutputStream(String path)
This method returns a
FileOutputStream based on the provided path to the file. |
static String |
toHex(byte[] value)
Converts an array of bytes into a String representing the hexadecimal values of each byte in order.
|
static InputStream |
toInputStream(File file)
This method returns an
InputStream which needs to be closed, based on FileInputStream. |
static InputStream |
toInputStream(String filePath)
This method returns an
InputStream which needs to be closed, based on
FileInputStream. |
static InputStream |
toInputStream(String string,
String charset)
This method returns the
InputStream based on the given String and char set. |
static boolean |
x500PrincipalAreEquals(X500Principal firstX500Principal,
X500Principal secondX500Principal)
This method compares two
X500Principals. |
public static final byte[] EMPTY_BYTE_ARRAY
public static final String DEFAULT_DATE_TIME_FORMAT
public static final String DEFAULT_DATE_FORMAT
public static String formatInternal(Date date)
date - the date to be convertedpublic static String toHex(byte[] value)
value - the value to be converted to hexadecimalprotected static int toDigit(char ch,
int index)
throws DSSException
ch - A character to convert to an integer digitindex - The index of the character in the sourceDSSException - Thrown if ch is an illegal hex characterpublic static boolean resourceExists(String path)
path - public static boolean fileExists(String path)
path - public static File getFile(String filePath)
filePath - The path to the file.public static String convertToPEM(CertificateToken cert)
cert - the token to be converted to PEMpublic static boolean isStartWithASN1SequenceTag(InputStream is)
is - the inputstream to be testedpublic static byte[] convertToDER(String pemContent)
pemContent - the String which contains the PEM encoded objectpublic static CertificateToken loadCertificate(String path)
-----BEGIN CERTIFICATE-----, and must be bounded at the end by -----END CERTIFICATE-----.path - resource location.public static CertificateToken loadCertificate(File file)
-----BEGIN CERTIFICATE-----, and must be bounded at the end by -----END CERTIFICATE-----.file - the file with the certificatepublic static CertificateToken loadCertificate(InputStream inputStream)
-----BEGIN CERTIFICATE-----, and must be bounded at the end by -----END CERTIFICATE-----.inputStream - input stream containing the certificatepublic static Collection<CertificateToken> loadCertificateFromP7c(InputStream is)
public static CertificateToken loadCertificate(byte[] input)
DSSException or return null
when the
certificate cannot be loaded.input - array of bytes containing the certificatepublic static CertificateToken loadCertificateFromBase64EncodedString(String base64Encoded)
base64Encoded - the base64 encoded certificatepublic static Collection<CertificateToken> loadPotentialIssuerCertificates(CertificateToken cert, DataLoader loader)
cert - certificate for which the issuer(s) should be loadedloader - the data loader to usepublic static String getSHA1Digest(String stringToDigest)
stringToDigest - Everything in the namepublic static byte[] digest(DigestAlgorithm digestAlgorithm, byte[] data)
digestAlgorithm - the algorithm to usedata - the data to digestpublic static MessageDigest getMessageDigest(DigestAlgorithm digestAlgorithm)
digestAlgorithm - the digest algoritmpublic static byte[] digest(DigestAlgorithm digestAlgo, InputStream inputStream)
InputStream with the given algorithm.digestAlgo - the algorithm to useinputStream - the data to digestpublic static byte[] digest(DigestAlgorithm digestAlgorithm, DSSDocument document)
public static byte[] digest(DigestAlgorithm digestAlgorithm, byte[]... data)
public static InputStream toInputStream(String filePath) throws DSSException
InputStream which needs to be closed, based on
FileInputStream.filePath - The path to the file to readInputStream materialized by a FileInputStream representing the contents of the fileDSSExceptionpublic static InputStream toInputStream(File file)
InputStream which needs to be closed, based on FileInputStream.file - File to read.InputStream materialized by a FileInputStream
representing the contents of the file @ if an I/O error occurredpublic static InputStream toInputStream(String string, String charset) throws DSSException
InputStream based on the given String and char set. This stream does not
need to be closed, it is based on ByteArrayInputStream.string - String to convertcharset - char set to useInputStream based on ByteArrayInputStreamDSSExceptionpublic static FileOutputStream toFileOutputStream(String path) throws DSSException
FileOutputStream based on the provided path to the file.path - to the fileFileOutputStreamDSSExceptionpublic static InputStream toByteArrayInputStream(File file)
InputStream which does not need to be closed, based on
ByteArrayInputStream.file - File to readInputStream based on ByteArrayInputStreampublic static byte[] toByteArray(File file)
file - the file to read, must not be nullnullpublic static DSSDocument splitDocument(DSSDocument origin, int start, int end)
origin - the original documentstart - the start position to retrieveend - the end position to retrievepublic static byte[] toByteArray(DSSDocument document)
DSSDocument as a byte[].document - the document to readpublic static byte[] toByteArray(InputStream inputStream)
InputStream as a byte[].inputStream - the inputstream to readpublic static void saveToFile(byte[] bytes,
File file)
byte to the provided File.bytes - the binary to savefile - the file where to storepublic static String getDeterministicId(Date signingTime, TokenIdentifier id)
signingTime - the signing timeid - the token identifierpublic static String getMD5Digest(byte[] bytes)
bytes - the bytes to be digestedpublic static X500Principal getX500PrincipalOrNull(String x500PrincipalString)
X500Principal corresponding to the given string or null if the conversion
is not possible.x500PrincipalString - a String representation of the X500PrincipalX500Principal or nullpublic static boolean x500PrincipalAreEquals(X500Principal firstX500Principal, X500Principal secondX500Principal)
X500Principals. X500Principal.CANONICAL and
X500Principal.RFC2253 forms are compared.firstX500Principal - the first X500Principal object to be comparedsecondX500Principal - the second X500Principal object to be comparedpublic static X500Principal getNormalizedX500Principal(X500Principal x500Principal)
x500Principal - to be normalizedX500Principal normalizedpublic static InputStream getResource(String resourcePath)
public static Date getUtcDate(int year, int month, int day)
year - the value used to set the YEAR calendar field.month - the month. Month value is 0-based. e.g., 0 for January.day - the value used to set the DAY_OF_MONTH calendar field.public static String getMessageId(String message)
message - the String message on which the unique id is calculated.public static int available(InputStream is) throws DSSException
IOException if this input stream has been closed by
invoking the InputStream.close() method.
returns 0.0 when
it reaches the end of the input stream.DSSException - if IOException occurs (if an I/O error occurs)public static void printSecurityProviders()
public static String getSummaryMessage(Exception exception, Class<?> javaClass)
exception - Exception to summarizejavaClass - ClassString containing the summary messagepublic static int readToArray(DSSDocument dssDocument, int headerLength, byte[] destinationByteArray)
headerLength bytes from dssDocument to the given byte array.dssDocument - DSSDocument to readheaderLength - int: maximum number of bytes to readdestinationByteArray - destination byte arraypublic static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit)
date1 - the oldest datedate2 - the newest datetimeUnit - the unit in which you want the diffpublic static byte readFirstByte(DSSDocument dssDocument)
dssDocument - the documentpublic static byte[] concatenate(byte[]... arrays)
arrays - byte arrays to concatenatebyte arraypublic static String getFinalFileName(DSSDocument originalFile, SigningOperation operation, SignatureLevel level, ASiCContainerType containerType)
public static String getFinalFileName(DSSDocument originalFile, SigningOperation operation, SignatureLevel level)
Copyright © 2019. All rights reserved.