mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add methods
This commit is contained in:
parent
fd0948ca3c
commit
3ca429af58
@ -417,6 +417,111 @@ public class DigestUtil {
|
||||
return new Digester(DigestAlgorithm.SHA256).digestHex(file);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------- SHA-512
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return SHA-512摘要
|
||||
*/
|
||||
public static byte[] sha512(final byte[] data) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digest(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @param charset 编码
|
||||
* @return SHA-512摘要
|
||||
* @since 3.0.8
|
||||
*/
|
||||
public static byte[] sha512(final String data, final String charset) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digest(data, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算sha512摘要值,使用UTF-8编码
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return MD5摘要
|
||||
*/
|
||||
public static byte[] sha512(final String data) {
|
||||
return sha512(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return SHA-512摘要
|
||||
*/
|
||||
public static byte[] sha512(final InputStream data) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digest(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值
|
||||
*
|
||||
* @param file 被摘要文件
|
||||
* @return SHA-512摘要
|
||||
*/
|
||||
public static byte[] sha512(final File file) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digest(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-1摘要值,并转为16进制字符串
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return SHA-512摘要的16进制表示
|
||||
*/
|
||||
public static String sha512Hex(final byte[] data) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digestHex(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值,并转为16进制字符串
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @param charset 编码
|
||||
* @return SHA-512摘要的16进制表示
|
||||
*/
|
||||
public static String sha512Hex(final String data, final String charset) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digestHex(data, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值,并转为16进制字符串
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return SHA-512摘要的16进制表示
|
||||
*/
|
||||
public static String sha512Hex(final String data) {
|
||||
return sha512Hex(data, CharsetUtil.NAME_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值,并转为16进制字符串
|
||||
*
|
||||
* @param data 被摘要数据
|
||||
* @return SHA-512摘要的16进制表示
|
||||
*/
|
||||
public static String sha512Hex(final InputStream data) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digestHex(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算SHA-512摘要值,并转为16进制字符串
|
||||
*
|
||||
* @param file 被摘要文件
|
||||
* @return SHA-512摘要的16进制表示
|
||||
*/
|
||||
public static String sha512Hex(final File file) {
|
||||
return new Digester(DigestAlgorithm.SHA512).digestHex(file);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------- Hmac
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test;
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.crypto.BCUtil;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test;
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.GlobalBouncyCastleProvider;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test;
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test;
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
@ -1,9 +1,6 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
package cn.hutool.crypto.asymmetric;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricCrypto;
|
||||
import cn.hutool.crypto.asymmetric.ECIES;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
package cn.hutool.crypto.asymmetric;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
@ -8,9 +8,6 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
package cn.hutool.crypto.asymmetric;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
@ -8,8 +8,6 @@ import cn.hutool.crypto.ECKeyUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.SmUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.SM2;
|
||||
import org.bouncycastle.crypto.engines.SM2Engine;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.jcajce.spec.OpenSSHPrivateKeySpec;
|
@ -1,10 +1,8 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
package cn.hutool.crypto.asymmetric;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import cn.hutool.crypto.digest.BCrypt;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.digest.mac.Mac;
|
@ -1,12 +1,10 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.crypto.digest.Digester;
|
||||
|
||||
/**
|
||||
* 摘要算法单元测试
|
||||
@ -73,4 +71,11 @@ public class DigestTest {
|
||||
final String hex = DigestUtil.sha256Hex(testStr);
|
||||
Assert.assertEquals(64, hex.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hash512Test() {
|
||||
final String testStr = "Test中文";
|
||||
final String hex = DigestUtil.sha512Hex(testStr);
|
||||
Assert.assertEquals(128, hex.length());
|
||||
}
|
||||
}
|
@ -1,11 +1,9 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.digest.HMac;
|
||||
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.ZUC;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
@ -1,10 +1,8 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.crypto.digest.MD5;
|
||||
|
||||
/**
|
||||
* MD5 单元测试
|
||||
*
|
@ -1,7 +1,6 @@
|
||||
package cn.hutool.crypto.test.digest;
|
||||
package cn.hutool.crypto.digest;
|
||||
|
||||
import cn.hutool.core.codec.Base32;
|
||||
import cn.hutool.crypto.digest.HmacAlgorithm;
|
||||
import cn.hutool.crypto.digest.otp.HOTP;
|
||||
import cn.hutool.crypto.digest.otp.TOTP;
|
||||
import org.junit.Assert;
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
@ -6,7 +6,6 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.symmetric.ChaCha20;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,10 +1,9 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.symmetric.DES;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
@ -1,11 +1,9 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.crypto.symmetric.RC4;
|
||||
|
||||
public class RC4Test {
|
||||
|
||||
@Test
|
@ -1,6 +1,5 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.crypto.symmetric.SM4;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
@ -9,12 +9,6 @@ import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.symmetric.AES;
|
||||
import cn.hutool.crypto.symmetric.DES;
|
||||
import cn.hutool.crypto.symmetric.DESede;
|
||||
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import cn.hutool.crypto.symmetric.Vigenere;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
import cn.hutool.crypto.symmetric.XXTEA;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,8 +1,7 @@
|
||||
package cn.hutool.crypto.test.symmetric;
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.symmetric.ZUC;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package cn.hutool.crypto.test.symmetric.fpe;
|
||||
package cn.hutool.crypto.symmetric.fpe;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.crypto.symmetric.fpe.FPE;
|
||||
import org.bouncycastle.crypto.util.BasicAlphabetMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
Loading…
x
Reference in New Issue
Block a user