加密相关工具类直接使用Spring util封装,减少jar依赖

类名: DigestUtil

md5

/**
* Calculates the MD5 digest.
*
* @param bytes Data to digest
* @return MD5 digest as a hex array
*/
DigestUtil.md5(byte[] bytes);

md5

/**
* Calculates the MD5 digest.
*
* @param data Data to digest
* @return MD5 digest as a hex array
*/
DigestUtil.md5(String data);

md5Hex

/**
* Calculates the MD5 digest and returns the value as a 32 character hex string.
*
* @param data Data to digest
* @return MD5 digest as a hex string
*/
DigestUtil.md5Hex(String data);

md5Hex

/**
* Return a hexadecimal string representation of the MD5 digest of the given bytes.
*
* @param bytes the bytes to calculate the digest over
* @return a hexadecimal digest string
*/
DigestUtil.md5Hex(byte[] bytes);

sha1

/**
* sha1
*
* @param data Data to digest
* @return digest as a hex array
*/
DigestUtil.sha1(String data);

sha1

/**
* sha1
*
* @param bytes Data to digest
* @return digest as a hex array
*/
DigestUtil.sha1(byte[] bytes);

sha1Hex

/**
* sha1Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
DigestUtil.sha1Hex(String data);

sha1Hex

/**
* sha1Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.sha1Hex(byte[] bytes);

sha224

/**
* SHA224
*
* @param data Data to digest
* @return digest as a byte array
*/
DigestUtil.sha224(String data);

sha224

/**
* SHA224
*
* @param bytes Data to digest
* @return digest as a byte array
*/
DigestUtil.sha224(byte[] bytes);

sha224Hex

/**
* SHA224Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
DigestUtil.sha224Hex(String data);

sha224Hex

/**
* SHA224Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.sha224Hex(byte[] bytes);

sha256

/**
* sha256Hex
*
* @param data Data to digest
* @return digest as a byte array
*/
DigestUtil.sha256(String data);

sha256

/**
* sha256Hex
*
* @param bytes Data to digest
* @return digest as a byte array
*/
DigestUtil.sha256(byte[] bytes);

sha256Hex

/**
* sha256Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
DigestUtil.sha256Hex(String data);

sha256Hex

/**
* sha256Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.sha256Hex(byte[] bytes);

sha384

/**
* sha384
*
* @param data Data to digest
* @return digest as a byte array
*/
DigestUtil.sha384(String data);

sha384

/**
* sha384
*
* @param bytes Data to digest
* @return digest as a byte array
*/
DigestUtil.sha384(byte[] bytes);

sha384Hex

/**
* sha384Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
DigestUtil.sha384Hex(String data);

sha384Hex

/**
* sha384Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.sha384Hex(byte[] bytes);

sha512

/**
* sha512Hex
*
* @param data Data to digest
* @return digest as a byte array
*/
DigestUtil.sha512(String data);

sha512

/**
* sha512Hex
*
* @param bytes Data to digest
* @return digest as a byte array
*/
DigestUtil.sha512(byte[] bytes);

sha512Hex

/**
* sha512Hex
*
* @param data Data to digest
* @return digest as a hex string
*/
DigestUtil.sha512Hex(String data);

sha512Hex

/**
* sha512Hex
*
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.sha512Hex(byte[] bytes);

digest

/**
* digest
*
* @param algorithm 算法
* @param bytes Data to digest
* @return digest byte array
*/
DigestUtil.digest(String algorithm, byte[] bytes);

digestHex

/**
* digest Hex
*
* @param algorithm 算法
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.digestHex(String algorithm, byte[] bytes);

hmacMd5

/**
* hmacMd5
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacMd5(String data, String key);

hmacMd5

/**
* hmacMd5
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacMd5(byte[] bytes, String key);

hmacMd5Hex

/**
* hmacMd5 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacMd5Hex(String data, String key);

hmacMd5Hex

/**
* hmacMd5 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacMd5Hex(byte[] bytes, String key);

hmacSha1

/**
* hmacSha1
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha1(String data, String key);

hmacSha1

/**
* hmacSha1
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha1(byte[] bytes, String key);

hmacSha1Hex

/**
* hmacSha1 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha1Hex(String data, String key);

hmacSha1Hex

/**
* hmacSha1 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha1Hex(byte[] bytes, String key);

hmacSha224

/**
* hmacSha224
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha224(String data, String key);

hmacSha224

/**
* hmacSha224
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha224(byte[] bytes, String key);

hmacSha224Hex

/**
* hmacSha224 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha224Hex(String data, String key);

hmacSha224Hex

/**
* hmacSha224 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha224Hex(byte[] bytes, String key);

hmacSha256

/**
* hmacSha256
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha256(String data, String key);

hmacSha256

/**
* hmacSha256
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha256(byte[] bytes, String key);

hmacSha256Hex

/**
* hmacSha256 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha256Hex(String data, String key);

hmacSha256Hex

/**
* hmacSha256 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha256Hex(byte[] bytes, String key);

hmacSha384

/**
* hmacSha384
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha384(String data, String key);

hmacSha384

/**
* hmacSha384
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha384(byte[] bytes, String key);

hmacSha384Hex

/**
* hmacSha384 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha384Hex(String data, String key);

hmacSha384Hex

/**
* hmacSha384 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha384Hex(byte[] bytes, String key);

hmacSha512

/**
* hmacSha512
*
* @param data Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha512(String data, String key);

hmacSha512

/**
* hmacSha512
*
* @param bytes Data to digest
* @param key key
* @return digest as a byte array
*/
DigestUtil.hmacSha512(byte[] bytes, String key);

hmacSha512Hex

/**
* hmacSha512 Hex
*
* @param data Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha512Hex(String data, String key);

hmacSha512Hex

/**
* hmacSha512 Hex
*
* @param bytes Data to digest
* @param key key
* @return digest as a hex string
*/
DigestUtil.hmacSha512Hex(byte[] bytes, String key);

digestHmacHex

/**
* digest Hmac Hex
*
* @param algorithm 算法
* @param bytes Data to digest
* @return digest as a hex string
*/
DigestUtil.digestHmacHex(String algorithm, byte[] bytes, String key);

digestHmac

/**
* digest Hmac
*
* @param algorithm 算法
* @param bytes Data to digest
* @return digest as a byte array
*/
DigestUtil.digestHmac(String algorithm, byte[] bytes, String key);

encodeHex

/**
* encode Hex
*
* @param bytes Data to Hex
* @return bytes as a hex string
*/
DigestUtil.encodeHex(byte[] bytes);

decodeHex

/**
* decode Hex
*
* @param hexStr Hex string
* @return decode hex to bytes
*/
DigestUtil.decodeHex(String hexStr);

slowEquals

/**
* 比较字符串,避免字符串因为过长,产生耗时
*
* @param a String
* @param b String
* @return 是否相同
*/
DigestUtil.slowEquals(String a, String b);

slowEquals

/**
* 比较 byte 数组,避免字符串因为过长,产生耗时
*
* @param a byte array
* @param b byte array
* @return 是否相同
*/
DigestUtil.slowEquals(byte[] a, byte[] b);

微信 vs 公众号

如梦技术

精彩内容每日推荐!!!