Hashes a string using the MD2 algorithm.

@since 1.1
@param data the string to hash
@param charset the charset of the string
@return the MD2 hash of the string
@throws NoSuchAlgorithmException the algorithm is not supported by existing providers
14686
public static byte[] md2Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return md2Hash(data.getBytes(charset));
	}
1239261
public static byte[] sha1Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return sha1Hash(data.getBytes(charset));
	}
438113
@Override
    public byte[] decode(final String data) {
        return data != null ? data.getBytes(CHARSET) : null;
    }
98576
public static byte[] sha384Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return sha384Hash(data.getBytes(charset));
	}
126656
public static byte[] computeHash(String passwd) throws NoSuchAlgorithmException  {
        java.security.MessageDigest md = java.security.MessageDigest.getInstance("SHA-1");
        md.reset();
        md.update(passwd.getBytes());
        return md.digest();
    }
481800
public static String encryptMD5(String data) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            return copyValueOf(Hex.encodeHex(digest.digest(data.getBytes(StandardCharsets.UTF_8))));
        } catch (final NoSuchAlgorithmException ex) {
            throw new TechnicalException("Failed to instantiate an MD5 algorithm", ex);
        }
    }
645690
public static Set<String> ngramOnCharacter2Set(String data,int[] gramSizes) {
        // 提取ngram
        Set<String> list = new HashSet<String>();
        ngramOnCharacter(data, gramSizes, list);
        return list;
    }
649173
public static byte[] hashToBytes(final char[] data, final long seed) {
    if ((data == null) || (data.length == 0)) {
      return null;
    }
    return toByteArray(hash(data, seed));
  }
384102
public static long createHash(byte[] data) {
        long h = 0;
        byte[] res;

        synchronized (digestFunction) {
            res = digestFunction.digest(data);
        }

        for (int i = 0; i < 4; i++) {
            h <<= 8;
            h |= ((int) res[i]) & 0xFF;
        }
        return h;
    }
190555
public static String hash(final String str)
        {
        try
            {
            final MessageDigest md = new Sha1();
            final byte[] hashed = md.digest(str.getBytes("UTF-8"));
            final byte[] encoded = Base64.encodeBase64(hashed);
            return new String(encoded, "UTF-8");
            }
        catch (final UnsupportedEncodingException e)
            {
            LOG.error("Encoding error??", e);
            return "";
            }
        }
1158230
public static String hexSHA512(String data) {
        Objects.requireNonNull(data, Required.DATA.toString());
        
        return DigestUtils.sha512Hex(data);
    }
809795
public static String sha256Hex(String data, String charset) {
		return new Digester(DigestAlgorithm.SHA256).digestHex(data, charset);
	}
1329286
public byte[] decryptFromBcd(String data, KeyType keyType, Charset charset) {
		final byte[] dataBytes = BCD.ascToBcd(StrUtil.bytes(data, charset));
		return decrypt(dataBytes, keyType);
	}
436501
public static void hash(byte[] data, byte[] output) {
    int len = output.length;
    if (len == 0)
      return;
    int[] code = calculate(data);
    for (int outIndex = 0, codeIndex = 0, shift = 24;
            outIndex < len && codeIndex < 5;
                ++outIndex, shift -= 8) {
      output[outIndex] = (byte) (code[codeIndex] >>> shift);
      if (shift == 0) {
        shift = 32;     // will be decremented by 8 before next iteration
        ++codeIndex;
      }
    }
  }
1081834
public function crypt(string $data) {
        $keyHash = md5(Config::getConfig()->encrypt->key);
        $key = substr($keyHash, 0, mcrypt_get_key_size(self::$cipher, self::$mode));
        $iv = substr($keyHash, 0, mcrypt_get_block_size(self::$cipher, self::$mode));
        return base64_encode(mcrypt_encrypt(self::$cipher, $key, $data, self::$mode, $iv));
    }
1334271
@SuppressWarnings("deprecation")
	public final static HashFunction forName(final String messageDigest) throws NoSuchAlgorithmException {
		if ("".equals(messageDigest)) return null;
		if ("MD5".equalsIgnoreCase(messageDigest)) return Hashing.md5();
		if ("MurmurHash3".equalsIgnoreCase(messageDigest)) return Hashing.murmur3_128();
		throw new NoSuchAlgorithmException("Unknown hash function " + messageDigest);
	}
1183242
public static String getHashText(String plainText, String algorithm) throws NoSuchAlgorithmException {
	MessageDigest mdAlgorithm = MessageDigest.getInstance(algorithm);

	mdAlgorithm.update(plainText.getBytes());

	byte[] digest = mdAlgorithm.digest();
	StringBuffer hexString = new StringBuffer();

	for (int i = 0; i < digest.length; i++) {
	    plainText = Integer.toHexString(0xFF & digest[i]);

	    if (plainText.length() < 2) {
		plainText = "0" + plainText;
	    }

	    hexString.append(plainText);
	}

	return hexString.toString();
    }