goja-core/src/main/java/goja/core/encry/DigestsKit.java
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);

            if (salt != null) {
                digest.update(salt);
            }

            byte[] result = digest.digest(input);

            for (int i = 1; i < iterations; i++) {
                digest.reset();
                result = digest.digest(result);
            }
            return result;
        } catch (GeneralSecurityException e) {
            throw ExceptionKit.unchecked(e);
        }
    }
private static byte[] digest(byte[] input, String algorithm, byte[] salt, int iterations) {
        try {
            MessageDigest digest = MessageDigest.getInstance(algorithm);

            if (salt != null) {
                digest.update(salt);
            }

            byte[] result = digest.digest(input);

            for (int i = 1; i < iterations; i++) {
                digest.reset();
                result = digest.digest(result);
            }
            return result;
        } catch (GeneralSecurityException e) {
            throw ExceptionKit.unchecked(e);
        }
    }
private static byte [ ] digest ( byte [ ] input , String algorithm , byte [ ] salt , int iterations ) { try { MessageDigest digest = MessageDigest . getInstance ( algorithm ) ; if ( salt != null ) { digest . update ( salt ) ; } byte [ ] result = digest . digest ( input ) ; for ( int i = 1 ; i < iterations ; i ++ ) { digest . reset ( ) ; result = digest . digest ( result ) ; } return result ; } catch ( GeneralSecurityException e ) { throw ExceptionKit . unchecked ( e ) ; } }
对字符串进行散列, 支持md5与sha1算法.
对字符串进行散列 支持md5与sha1算法 .