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

codes.draeger.replayguard.core.SecurityUtils.kt Maven / Gradle / Ivy

Go to download

ReplayGuard is a security-focused library designed to enhance the security of communications between client applications and backend servers. This library addresses the critical need for secure data transmission, specifically targeting the vulnerabilities associated with replay attacks and unauthorized data interception.

The newest version!
package codes.draeger.replayguard.core

import java.security.SecureRandom
import java.time.Instant

object SecurityUtils {
    /**
     * Generates a cryptographically strong random nonce.
     *
     * This method creates a 16-byte nonce using a secure random number generator.
     * The generated nonce is a sequence of random bytes, formatted as a hexadecimal string.
     *
     * @return A hexadecimal string representing the randomly generated nonce.
     */
    fun generateNonce(): String =
        ByteArray(16).also { SecureRandom().nextBytes(it) }
            .joinToString("") { "%02x".format(it) }

    /**
     * Retrieves the current Unix timestamp in seconds (UTC).
     *
     * @return The current Unix timestamp as a long value.
     */
    fun getCurrentTimestamp(): Long = Instant.now().epochSecond
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy