
io.jsync.utils.Token Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsync.io Show documentation
Show all versions of jsync.io Show documentation
jsync.io is a non-blocking, event-driven networking framework for Java
package io.jsync.utils;
import io.jsync.buffer.Buffer;
import java.util.UUID;
import java.util.zip.CRC32;
public class Token {
private CRC32 crc32;
private Token() {
Buffer tokenBuff = new Buffer();
tokenBuff.appendString(CryptoUtils.calculateHmacSHA1(
UUID.randomUUID().toString(),
UUID.randomUUID().toString()));
tokenBuff.appendLong(UUID.randomUUID().variant());
CRC32 crc32 = new CRC32();
crc32.update(tokenBuff.getBytes());
this.crc32 = crc32;
}
public static long generate() {
return generateToken().getLong();
}
public static Token generateToken() {
return new Token();
}
public long getLong() {
return crc32.getValue();
}
public String toHex() {
return String.format("%x", crc32.getValue());
}
public String toString() {
return toHex();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy