groovy-extensions/groovy-crypt
2024-07-23 16:25:09 +02:00
..
src update to Groovy 4.0.3 2022-06-17 10:53:57 +02: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
gradle.properties update dependencies, update to groovy 4.0.22 2024-07-23 16:25:09 +02:00
LICENSE.txt initial commit 2021-11-04 16:28:10 +01:00
README.adoc update to Groovy 4.0.3 2022-06-17 10:53:57 +02:00

= Groovy crypt library

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)
        }