Skip to content

Latest commit

 

History

History
79 lines (56 loc) · 2.22 KB

README.md

File metadata and controls

79 lines (56 loc) · 2.22 KB

Module kipher-mac

API Documentation

Library for ensuring data integrity and authenticity using message authentication codes.

Adding Dependency

Maven Central Sonatype Nexus (Snapshots)

Gradle

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

Maven

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

Usage

import io.github.jhdcruz.kipher.mac.Mac

// adjust syntax for other JVM languages (ex. java).
fun main() {
    val mac = Mac(MacModes.Poly1305) // replace with desired mode

    val data = "sample data".encodeToByteArray()

    val mac = mac.generateMac(data) // returns Map
    // or,
    val hashString = mac.generateMacString(data) // returns hex string

    // Verifying hashes
    println(mac.verifyMac(data, hash)) // returns true
    // or,
    println(mac.verifyMac(data, hashString)) // returns true
}

Hashing from multiple data

import io.github.jhdcruz.kipher.mac.Mac

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

class MacTest {

    fun main() {
        val mac = Mac(MacModes.Poly1305) // replace with desired mode

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

        val mac = mac.generateMac(data) // returns Map
        // or,
        val hashString = mac.generateMacString(data) // returns hex string

        // Verifying hashes
        println(mac.verifyMac(data, hash)) // returns true
        // or,
        println(mac.verifyMac(data, hashString)) // returns true
    }
}