groovy-extensions/groovy-crypt
2021-12-18 20:30:31 +01:00
..
src initial commit 2021-11-04 16:28:10 +01:00
build.gradle update to gradle 7.3, move to group org.xbib.grrovy, remove log4j, repair spock tests 2021-12-12 20:27:59 +01:00
CREDITS.txt initial commit 2021-11-04 16:28:10 +01:00
LICENSE.txt initial commit 2021-11-04 16:28:10 +01:00
README.adoc initial commit 2021-11-04 16:28:10 +01:00

= Groovy crypt library

image:https://api.travis-ci.org/xbib/groovy-crypt.svg[title="Build status", link="https://travis-ci.org/xbib/groovy-crypt/"]
image:https://maven-badges.herokuapp.com/maven-central/org.xbib.groovy/groovy-crypt/badge.svg[title="Maven Central", link="http://search.maven.org/#search%7Cga%7C1%7Cxbib%20groovy-crypt"]
image:https://img.shields.io/badge/License-Apache%202.0-blue.svg[title="Apache License 2.0", link="https://opensource.org/licenses/Apache-2.0"]
image:https://img.shields.io/twitter/url/https/twitter.com/xbib.svg?style=social&label=Follow%20%40xbib[title="Twitter", link="https://twitter.com/xbib"]

image:https://sonarqube.com/api/badges/gate?key=org.xbib.groovy:groovy-crypt[title="Quality Gate", link="https://sonarqube.com/dashboard/index?id=org.xbib.groovy%3Agroovy-crypt"]
image:https://sonarqube.com/api/badges/measure?key=org.xbib.groovy:groovy-crypt&metric=coverage[title="Coverage", link="https://sonarqube.com/dashboard/index?id=org.xbib.groovy%3Agroovy-crypt"]
image:https://sonarqube.com/api/badges/measure?key=org.xbib.groovy:groovy-crypt&metric=vulnerabilities[title="Vulnerabilities", link="https://sonarqube.com/dashboard/index?id=org.xbib.groovy%3Agroovy-crypt"]
image:https://sonarqube.com/api/badges/measure?key=org.xbib.groovy:groovy-crypt&metric=bugs[title="Bugs", link="https://sonarqube.com/dashboard/index?id=org.xbib.groovy%3Agroovy-crypt"]
image:https://sonarqube.com/api/badges/measure?key=org.xbib.groovy:groovy-crypt&metric=sqale_debt_ratio[title="Technical debt ratio", link="https://sonarqube.com/dashboard/index?id=org.xbib.groovy%3Agroovy-crypt"]

This Groovy crypt implementation  of the `crypt(3)` function provided in the GNU C library (glibc)
was derived from crypt4j by Carl Harris https://github.com/soulwing/crypt4j

This implementation supports the MD5, SHA, SHA-256, and SHA-512 variants.
Additionally, it supports legacy DES and HMAC.

It is useful for LDAP passwords or secure cookie handling.

= Usage

        void testHMAC() {
            String s = "Hello World"
            String secret = "secret"
            String code = CryptUtil.hmac(s, secret, "HmacSHA1")
            assertEquals("858da8837b87f04b052c0f6e954c3f7bbe081164", code)
        }

        void testSHA() {
            String plaintext = 'geheim'
            String code = CryptUtil.sha(plaintext)
            assertEquals('SHA algorithm',
                    '{sha}kGByAB793z4R5tK1eC9Hd/4Dhzk=', code)
        }

        void testSSHA256() {
            String plaintext = 'geheim'
            byte[] salt = "467dd5b71e8d0f9e".decodeHex()
            String code = CryptUtil.ssha256(plaintext, salt)
            assertEquals('test SSHA-256 method',
                    '{ssha256}9yT5rYItjXK+mY8sKNBcKsKSnlY6ysTg8wbDVmAguTFGfdW3Ho0Png==', code)
        }

        void testSSHA512() {
            String plaintext = 'geheim'
            byte[] salt = "3c68f1f47f41d82f".decodeHex()
            String code = CryptUtil.ssha512(plaintext, salt)
            assertEquals('test SSHA-512 method',
                    '{ssha512}jeWuCXRjsvKh/vK548GP9ZCs4q9Sh1u700C8eONyV+EL/P810C8vlx9Eu4vRjHq/TDoGW8FE1l/P2KG3w9lHITxo8fR/Qdgv', code)
        }