guid-sta
is a small and simple java utility library that simplifies the process of generating GUIDs.
<repository>
<id>uk.ac.standrews.cs.maven.repository</id>
<name>School of Computer Science Maven Repository</name>
<url>http://maven.cs.st-andrews.ac.uk/</url>
</repository>
<dependency>
<groupId>uk.ac.standrews.cs</groupId>
<artifactId>guid-sta</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
You can generate GUIDs and PIDs via the GUIDFactory
and the PIDFactory
.
IGUID guid = GUIDFactory.generateRandomGUID(ALGORITHM.SHA1);
System.out.println(guid.toString());
Output is:
$ 23cec17ec246418a8e82fcc97d70adfe
You can also generate a GUID given its string version:
IGUID guid = GUIDFactory.recreateGUID("SHA1_16_23cec17ec246418a8e82fcc97d70adfe");
System.out.println(guid.toString());
Output is:
$ 23cec17ec246418a8e82fcc97d70adfe
Otherwise, you can generate a brand new GUID given an string as input (or an InputStream):
IGUID guid = GUIDFactory.generateGUID(ALGORITHM.SHA1, "TEST"); // This method can also take an InputStream as input
System.out.println(guid.toString());
Output is:
$ 984816fd329622876e14907634264e6f332e9fb3
- SHA1
- SHA256
- SHA384
- SHA512
- HEX
- CANON (HEX, but with 8-4-4-4-12 pattern)
- BASE_64
- UUID
- ETags
- Encode length of Key as in multiformats
This project originates from the asa project developed by Alan Dearle, Graham Kirby, and Stuart Norcross (University of St Andrews).
This project is currently maintained by Simone I. Conte (University of St Andrews).