DSSUtils { public static String getDeterministicId(final Date signingTime, TokenIdentifier id) { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos)) { if (signingTime != null) { dos.writeLong(signingTime.getTime()); } if (id != null) { dos.writeChars(id.asXmlId()); } dos.flush(); return "id-" + getMD5Digest(baos.toByteArray()); } catch (IOException e) { throw new DSSException(e); } } private  DSSUtils(); static String formatInternal(final Date date); static String formatDateWithCustomFormat(final Date date, final String format); static String toHex(final byte[] value); static String convertToPEM(final CertificateToken cert); static boolean isStartWithASN1SequenceTag(InputStream is); static byte[] convertToDER(String pemContent); static CertificateToken loadCertificate(final File file); static CertificateToken loadCertificate(final InputStream inputStream); static Collection<CertificateToken> loadCertificateFromP7c(InputStream is); static CertificateToken loadCertificate(final byte[] input); static CertificateToken loadCertificateFromBase64EncodedString(final String base64Encoded); static Collection<CertificateToken> loadPotentialIssuerCertificates(final CertificateToken cert, final DataLoader loader); static String getSHA1Digest(final String stringToDigest); static byte[] digest(final DigestAlgorithm digestAlgorithm, final byte[] data); static MessageDigest getMessageDigest(DigestAlgorithm digestAlgorithm); static byte[] encodeRSADigest(final DigestAlgorithm digestAlgorithm, final byte[] digest); static byte[] digest(final DigestAlgorithm digestAlgo, final InputStream inputStream); static byte[] digest(DigestAlgorithm digestAlgorithm, DSSDocument document); static byte[] digest(DigestAlgorithm digestAlgorithm, byte[]... data); static InputStream toInputStream(final File file); static InputStream toByteArrayInputStream(final File file); static byte[] toByteArray(final File file); static DSSDocument splitDocument(DSSDocument origin, int start, int end); static byte[] toByteArray(final DSSDocument document); static byte[] toByteArray(final InputStream inputStream); static CMSSignedData toCMSSignedData(final DSSDocument document); static boolean isTimestampToken(final DSSDocument document); static long getFileByteSize(DSSDocument dssDocument); static void saveToFile(final byte[] bytes, final File file); static String getNormalizedString(final String str); static String getDeterministicId(final Date signingTime, TokenIdentifier id); static String getMD5Digest(byte[] bytes); static X500Principal getX500PrincipalOrNull(final String x500PrincipalString); static Date getUtcDate(final int year, final int month, final int day); static void printSecurityProviders(); static byte readFirstByte(final DSSDocument dssDocument); static boolean compareFirstBytes(final DSSDocument dssDocument, byte[] byteArray); static byte[] concatenate(byte[]... arrays); static String decodeUrl(String uri); static long skipAvailableBytes(InputStream is, long n); static long readAvailableBytes(DSSDocument dssDocument, byte[] b); static long readAvailableBytes(InputStream is, byte[] b); static long readAvailableBytes(InputStream is, byte[] b, int off, int len); static String encodeURI(String fileURI); static String getExceptionMessage(Exception e); static Digest getDigest(DigestAlgorithm digestAlgo, DSSDocument dssDocument); static String removeControlCharacters(String str); static final byte[] EMPTY_BYTE_ARRAY; }
@Test public void getDeterministicId() throws InterruptedException { Date d1 = new Date(); String deterministicId = DSSUtils.getDeterministicId(d1, certificateWithAIA.getDSSId()); assertNotNull(deterministicId); String deterministicId2 = DSSUtils.getDeterministicId(d1, certificateWithAIA.getDSSId()); assertEquals(deterministicId, deterministicId2); assertNotNull(DSSUtils.getDeterministicId(null, certificateWithAIA.getDSSId())); Thread.sleep(1); String deterministicId3 = DSSUtils.getDeterministicId(new Date(), certificateWithAIA.getDSSId()); assertNotEquals(deterministicId2, deterministicId3); }