goja-core/src/main/java/goja/core/kits/lang/KeyCodeKit.java
private static String digestPassword(String password) {
        try {
            SecureRandom random = new SecureRandom();
            byte[] salt = new byte[EncodeKit.SALT_SIZE];
            random.nextBytes(salt);

            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(salt);
            md.update(password.getBytes());
            byte[] digest = md.digest();

            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(salt) + encoder.encode(digest);
        } catch (NoSuchAlgorithmException ne) {
            System.err.println(ne.toString());
            return null;
        } catch (Exception e) {
            System.err.println(e.toString());
            return null;
        }
    }
private static String digestPassword(String password) {
        try {
            SecureRandom random = new SecureRandom();
            byte[] salt = new byte[EncodeKit.SALT_SIZE];
            random.nextBytes(salt);

            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(salt);
            md.update(password.getBytes());
            byte[] digest = md.digest();

            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(salt) + encoder.encode(digest);
        } catch (NoSuchAlgorithmException ne) {
            System.err.println(ne.toString());
            return null;
        } catch (Exception e) {
            System.err.println(e.toString());
            return null;
        }
    }
private static String digestPassword ( String password ) { try { SecureRandom random = new SecureRandom ( ) ; byte [ ] salt = new byte [ EncodeKit . SALT_SIZE ] ; random . nextBytes ( salt ) ; MessageDigest md = MessageDigest . getInstance ( "MD5" ) ; md . update ( salt ) ; md . update ( password . getBytes ( ) ) ; byte [ ] digest = md . digest ( ) ; BASE64Encoder encoder = new BASE64Encoder ( ) ; return encoder . encode ( salt ) + encoder . encode ( digest ) ; } catch ( NoSuchAlgorithmException ne ) { System . err . println ( ne . toString ( ) ) ; return null ; } catch ( Exception e ) { System . err . println ( e . toString ( ) ) ; return null ; } }
加密

@param password 需要加密的字符串
加密