You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
groovy-extensions/groovy-crypt
Jörg Prante 13bba1c0fc update dependencies, update to groovy 4.0.22 2 months ago
..
src update to Groovy 4.0.3 2 years ago
CREDITS.txt initial commit 3 years ago
LICENSE.txt initial commit 3 years ago
README.adoc update to Groovy 4.0.3 2 years ago
build.gradle update to gradle 7.3, move to group org.xbib.grrovy, remove log4j, repair spock tests 3 years ago
gradle.properties update dependencies, update to groovy 4.0.22 2 months ago

README.adoc

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