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

