/** * Return a unique id for a date and the certificateToken id. * * @param signingTime * the signing time * @param id * the token identifier * @return an unique string */ 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); } }
@Test public void getMD5Digest() throws UnsupportedEncodingException { assertEquals("3e25960a79dbc69b674cd4ec67a72c62", DSSUtils.getMD5Digest("Hello world".getBytes("UTF-8"))); }