With Gradle:
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.vinceh121:tokenize4j:...'
}
With Maven:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.vinceh121</groupId>
<artifactId>tokenize4j</artifactId>
<version>...</version>
</dependency>
public class Main {
public static void main(String[] args) {
Tokenize tokenize = new Tokenize("very secure private key".getBytes());
// Generation
Token token = tokenize.generateToken(account);
System.out.println(token); // xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx
// Validation
String rawToken = "xxxxxxxx.xxxxxxxxxxx.xxxxxxxxx";
Token token;
try {
token = tokenize.validateToken(rawToken, id -> Database.fetchAccount(id));
} catch (SecurityException e) {
System.out.println("Invalid token signature!");
}
}
}
This implementation is licensed under the BSD-3-Clause license.