All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jsync.utils.Token Maven / Gradle / Ivy

There is a newer version: 1.10.13
Show newest version
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