Skip to content

Latest commit

 

History

History
79 lines (56 loc) · 2.28 KB

README.md

File metadata and controls

79 lines (56 loc) · 2.28 KB

Module kipher-digest

API Documentation

Library for cryptographic hash functions (such as SHAs, MD5s).

Adding Dependency

Maven Central Sonatype Nexus (Snapshots)

Gradle

implementation("io.github.jhdcruz:kipher-digest:$version")

Maven

<dependency>
    <groupId>io.github.jhdcruz</groupId>
    <artifactId>kipher-digest</artifactId>
    <version>$version</version>
</dependency>

Usage

import io.github.jhdcruz.kipher.digest.Digest

// adjust syntax for other JVM languages (ex. java).

fun main() {
    val digest = Digest(DigestModes.SHA_256) // replace with desired mode

    val data = "sample data".encodeToByteArray()

    val hash = digest.generateHash(data) // returns ByteArray
    // or,
    val hashString = digest.generateHashString(data) // returns hex string

    // Verifying hashes
    println(digest.verifyHash(data, hash)) // returns true
    // or,
    println(digest.verifyHash(data, hashString)) // returns true
}

Hashing from multiple data

import io.github.jhdcruz.kipher.digest.Digest

// adjust syntax for other JVM languages (ex. java).

class DigestTest {

    fun main() {
        val digest = Digest(DigestModes.SHA_256) // replace with desired mode

        // accepts iterable data, gets processed in update()
        val dataList: List<ByteArray> = listOf(
            "test".encodeToByteArray(),
            "test2".encodeToByteArray(),
            "test3".encodeToByteArray(),
        )

        val hash = digest.generateHash(data) // returns ByteArray
        // or,
        val hashString = digest.generateHashString(data) // returns hex string

        // Verifying hashes
        println(digest.verifyHash(data, hash)) // returns true
        // or,
        println(digest.verifyHash(data, hashString)) // returns true
    }
}