mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-08-18 20:38:02 +08:00
del methods
This commit is contained in:
@@ -243,7 +243,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 生成RSA私钥,仅用于非对称加密<br>
|
||||
* 采用PKCS#8规范,此规范定义了私钥信息语法和加密私钥语法<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param key 密钥,必须为DER编码存储
|
||||
* @return RSA私钥 {@link PrivateKey}
|
||||
@@ -256,7 +256,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 生成私钥,仅用于非对称加密<br>
|
||||
* 采用PKCS#8规范,此规范定义了私钥信息语法和加密私钥语法<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param algorithm 算法,如RSA、EC、SM2等
|
||||
* @param key 密钥,PKCS#8格式
|
||||
@@ -271,7 +271,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成私钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param algorithm 算法,如RSA、EC、SM2等
|
||||
* @param keySpec {@link KeySpec}
|
||||
@@ -309,7 +309,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 生成RSA公钥,仅用于非对称加密<br>
|
||||
* 采用X509证书规范<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param key 密钥,必须为DER编码存储
|
||||
* @return 公钥 {@link PublicKey}
|
||||
@@ -322,7 +322,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 生成公钥,仅用于非对称加密<br>
|
||||
* 采用X509证书规范<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param key 密钥,必须为DER编码存储
|
||||
@@ -337,7 +337,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成公钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
* 算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory">...</a>
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param keySpec {@link KeySpec}
|
||||
@@ -358,7 +358,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥,仅用于非对称加密<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @return {@link KeyPair}
|
||||
@@ -375,7 +375,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param keySize 密钥模(modulus )长度
|
||||
@@ -387,7 +387,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param keySize 密钥模(modulus )长度
|
||||
@@ -406,7 +406,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param params {@link AlgorithmParameterSpec}
|
||||
@@ -419,7 +419,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param param {@link AlgorithmParameterSpec}
|
||||
@@ -433,7 +433,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* <p>
|
||||
* 对于非对称加密算法,密钥长度有严格限制,具体如下:
|
||||
@@ -467,7 +467,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
* 密钥对生成算法见:<a href="https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator">...</a>
|
||||
*
|
||||
* <p>
|
||||
* 对于非对称加密算法,密钥长度有严格限制,具体如下:
|
||||
@@ -663,7 +663,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取密钥库(Java Key Store,JKS) KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param keyFile 证书文件
|
||||
* @param password 密码
|
||||
@@ -677,9 +677,9 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取密钥库(Java Key Store,JKS) KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @param password 密码
|
||||
* @return {@link KeyStore}
|
||||
*/
|
||||
@@ -716,7 +716,7 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param type 类型
|
||||
* @param keyFile 证书文件
|
||||
@@ -737,10 +737,10 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param type 类型
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @param password 密码,null表示无密码
|
||||
* @return {@link KeyStore}
|
||||
*/
|
||||
@@ -794,9 +794,9 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取X.509 Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @param password 密码
|
||||
* @param alias 别名
|
||||
* @return {@link KeyStore}
|
||||
@@ -809,9 +809,9 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取X.509 Certification文件中的公钥<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: https://www.cnblogs.com/yinliang/p/10115519.html
|
||||
* see: <a href="https://www.cnblogs.com/yinliang/p/10115519.html">...</a>
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @return {@link KeyStore}
|
||||
* @since 4.5.2
|
||||
*/
|
||||
@@ -826,9 +826,9 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取X.509 Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @return {@link KeyStore}
|
||||
* @since 4.4.1
|
||||
*/
|
||||
@@ -839,10 +839,10 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param type 类型,例如X.509
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @param password 密码
|
||||
* @param alias 别名
|
||||
* @return {@link KeyStore}
|
||||
@@ -860,10 +860,10 @@ public class KeyUtil {
|
||||
/**
|
||||
* 读取Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
* see: <a href="http://snowolf.iteye.com/blog/391931">...</a>
|
||||
*
|
||||
* @param type 类型,例如X.509
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(File)} 读取
|
||||
* @return {@link Certificate}
|
||||
*/
|
||||
public static Certificate readCertificate(final String type, final InputStream in) {
|
||||
@@ -910,7 +910,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 编码压缩EC公钥(基于BouncyCastle)<br>
|
||||
* 见:https://www.cnblogs.com/xinzhao/p/8963724.html
|
||||
* 见:<a href="https://www.cnblogs.com/xinzhao/p/8963724.html">...</a>
|
||||
*
|
||||
* @param publicKey {@link PublicKey},必须为org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey
|
||||
* @return 压缩得到的X
|
||||
@@ -922,7 +922,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)<br>
|
||||
* 见:https://www.cnblogs.com/xinzhao/p/8963724.html
|
||||
* 见:<a href="https://www.cnblogs.com/xinzhao/p/8963724.html">...</a>
|
||||
*
|
||||
* @param encode 压缩公钥
|
||||
* @param curveName EC曲线名
|
||||
@@ -935,7 +935,7 @@ public class KeyUtil {
|
||||
|
||||
/**
|
||||
* 解码恢复EC压缩公钥,支持Base64和Hex编码,(基于BouncyCastle)<br>
|
||||
* 见:https://www.cnblogs.com/xinzhao/p/8963724.html
|
||||
* 见:<a href="https://www.cnblogs.com/xinzhao/p/8963724.html">...</a>
|
||||
*
|
||||
* @param encodeByte 压缩公钥
|
||||
* @param curveName EC曲线名
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.lang.Validator;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
import cn.hutool.crypto.digest.Digester;
|
||||
import cn.hutool.crypto.digest.HMac;
|
||||
@@ -29,19 +26,10 @@ import javax.crypto.Mac;
|
||||
import javax.crypto.SecretKey;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyStore;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Provider;
|
||||
import java.security.PublicKey;
|
||||
import java.security.Security;
|
||||
import java.security.Signature;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 安全相关工具类<br>
|
||||
@@ -54,219 +42,6 @@ import java.util.Map;
|
||||
*/
|
||||
public class SecureUtil {
|
||||
|
||||
/**
|
||||
* 默认密钥字节数
|
||||
*
|
||||
* <pre>
|
||||
* RSA/DSA
|
||||
* Default Keysize 1024
|
||||
* Keysize must be a multiple of 64, ranging from 512 to 1024 (inclusive).
|
||||
* </pre>
|
||||
*/
|
||||
public static final int DEFAULT_KEY_SIZE = KeyUtil.DEFAULT_KEY_SIZE;
|
||||
|
||||
/**
|
||||
* 生成 {@link SecretKey},仅用于对称加密和摘要算法密钥生成
|
||||
*
|
||||
* @param algorithm 算法,支持PBE算法
|
||||
* @return {@link SecretKey}
|
||||
*/
|
||||
public static SecretKey generateKey(final String algorithm) {
|
||||
return KeyUtil.generateKey(algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 {@link SecretKey},仅用于对称加密和摘要算法密钥生成
|
||||
*
|
||||
* @param algorithm 算法,支持PBE算法
|
||||
* @param keySize 密钥长度
|
||||
* @return {@link SecretKey}
|
||||
* @since 3.1.2
|
||||
*/
|
||||
public static SecretKey generateKey(final String algorithm, final int keySize) {
|
||||
return KeyUtil.generateKey(algorithm, keySize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 {@link SecretKey},仅用于对称加密和摘要算法密钥生成
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param key 密钥,如果为{@code null} 自动生成随机密钥
|
||||
* @return {@link SecretKey}
|
||||
*/
|
||||
public static SecretKey generateKey(final String algorithm, final byte[] key) {
|
||||
return KeyUtil.generateKey(algorithm, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 {@link SecretKey}
|
||||
*
|
||||
* @param algorithm DES算法,包括DES、DESede等
|
||||
* @param key 密钥
|
||||
* @return {@link SecretKey}
|
||||
*/
|
||||
public static SecretKey generateDESKey(final String algorithm, final byte[] key) {
|
||||
return KeyUtil.generateDESKey(algorithm, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成PBE {@link SecretKey}
|
||||
*
|
||||
* @param algorithm PBE算法,包括:PBEWithMD5AndDES、PBEWithSHA1AndDESede、PBEWithSHA1AndRC2_40等
|
||||
* @param key 密钥
|
||||
* @return {@link SecretKey}
|
||||
*/
|
||||
public static SecretKey generatePBEKey(final String algorithm, final char[] key) {
|
||||
return KeyUtil.generatePBEKey(algorithm, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成 {@link SecretKey},仅用于对称加密和摘要算法
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param keySpec {@link KeySpec}
|
||||
* @return {@link SecretKey}
|
||||
*/
|
||||
public static SecretKey generateKey(final String algorithm, final KeySpec keySpec) {
|
||||
return KeyUtil.generateKey(algorithm, keySpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成私钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param key 密钥
|
||||
* @return 私钥 {@link PrivateKey}
|
||||
*/
|
||||
public static PrivateKey generatePrivateKey(final String algorithm, final byte[] key) {
|
||||
return KeyUtil.generatePrivateKey(algorithm, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成私钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param keySpec {@link KeySpec}
|
||||
* @return 私钥 {@link PrivateKey}
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static PrivateKey generatePrivateKey(final String algorithm, final KeySpec keySpec) {
|
||||
return KeyUtil.generatePrivateKey(algorithm, keySpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成私钥,仅用于非对称加密
|
||||
*
|
||||
* @param keyStore {@link KeyStore}
|
||||
* @param alias 别名
|
||||
* @param password 密码
|
||||
* @return 私钥 {@link PrivateKey}
|
||||
*/
|
||||
public static PrivateKey generatePrivateKey(final KeyStore keyStore, final String alias, final char[] password) {
|
||||
return KeyUtil.generatePrivateKey(keyStore, alias, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成公钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param key 密钥
|
||||
* @return 公钥 {@link PublicKey}
|
||||
*/
|
||||
public static PublicKey generatePublicKey(final String algorithm, final byte[] key) {
|
||||
return KeyUtil.generatePublicKey(algorithm, key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成公钥,仅用于非对称加密<br>
|
||||
* 算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyFactory
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @param keySpec {@link KeySpec}
|
||||
* @return 公钥 {@link PublicKey}
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static PublicKey generatePublicKey(final String algorithm, final KeySpec keySpec) {
|
||||
return KeyUtil.generatePublicKey(algorithm, keySpec);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥,仅用于非对称加密<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @return {@link KeyPair}
|
||||
*/
|
||||
public static KeyPair generateKeyPair(final String algorithm) {
|
||||
return KeyUtil.generateKeyPair(algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param keySize 密钥模(modulus )长度
|
||||
* @return {@link KeyPair}
|
||||
*/
|
||||
public static KeyPair generateKeyPair(final String algorithm, final int keySize) {
|
||||
return KeyUtil.generateKeyPair(algorithm, keySize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param keySize 密钥模(modulus )长度
|
||||
* @param seed 种子
|
||||
* @return {@link KeyPair}
|
||||
*/
|
||||
public static KeyPair generateKeyPair(final String algorithm, final int keySize, final byte[] seed) {
|
||||
return KeyUtil.generateKeyPair(algorithm, keySize, seed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param params {@link AlgorithmParameterSpec}
|
||||
* @return {@link KeyPair}
|
||||
* @since 4.3.3
|
||||
*/
|
||||
public static KeyPair generateKeyPair(final String algorithm, final AlgorithmParameterSpec params) {
|
||||
return KeyUtil.generateKeyPair(algorithm, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用于非对称加密的公钥和私钥<br>
|
||||
* 密钥对生成算法见:https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#KeyPairGenerator
|
||||
*
|
||||
* @param algorithm 非对称加密算法
|
||||
* @param seed 种子
|
||||
* @param params {@link AlgorithmParameterSpec}
|
||||
* @return {@link KeyPair}
|
||||
* @since 4.3.3
|
||||
*/
|
||||
public static KeyPair generateKeyPair(final String algorithm, final byte[] seed, final AlgorithmParameterSpec params) {
|
||||
return KeyUtil.generateKeyPair(algorithm, seed, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用于密钥生成的算法<br>
|
||||
* 获取XXXwithXXX算法的后半部分算法,如果为ECDSA或SM2,返回算法为EC
|
||||
*
|
||||
* @param algorithm XXXwithXXX算法
|
||||
* @return 算法
|
||||
*/
|
||||
public static String getAlgorithmAfterWith(final String algorithm) {
|
||||
return KeyUtil.getAlgorithmAfterWith(algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成算法,格式为XXXwithXXX
|
||||
*
|
||||
@@ -280,116 +55,6 @@ public class SecureUtil {
|
||||
return StrUtil.format("{}with{}", digestPart, asymmetricAlgorithm.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成签名对象,仅用于非对称加密
|
||||
*
|
||||
* @param asymmetricAlgorithm {@link AsymmetricAlgorithm} 非对称加密算法
|
||||
* @param digestAlgorithm {@link DigestAlgorithm} 摘要算法
|
||||
* @return {@link Signature}
|
||||
*/
|
||||
public static Signature generateSignature(final AsymmetricAlgorithm asymmetricAlgorithm, final DigestAlgorithm digestAlgorithm) {
|
||||
try {
|
||||
return Signature.getInstance(generateAlgorithm(asymmetricAlgorithm, digestAlgorithm));
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
throw new CryptoException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取密钥库(Java Key Store,JKS) KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param password 密码
|
||||
* @return {@link KeyStore}
|
||||
*/
|
||||
public static KeyStore readJKSKeyStore(final InputStream in, final char[] password) {
|
||||
return KeyUtil.readJKSKeyStore(in, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取KeyStore文件<br>
|
||||
* KeyStore文件用于数字证书的密钥对保存<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param type 类型
|
||||
* @param in {@link InputStream} 如果想从文件读取.keystore文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param password 密码
|
||||
* @return {@link KeyStore}
|
||||
*/
|
||||
public static KeyStore readKeyStore(final String type, final InputStream in, final char[] password) {
|
||||
return KeyUtil.readKeyStore(type, in, password);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取X.509 Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param password 密码
|
||||
* @param alias 别名
|
||||
* @return {@link KeyStore}
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static Certificate readX509Certificate(final InputStream in, final char[] password, final String alias) {
|
||||
return KeyUtil.readX509Certificate(in, password, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取X.509 Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @return {@link KeyStore}
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static Certificate readX509Certificate(final InputStream in) {
|
||||
return KeyUtil.readX509Certificate(in);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param type 类型,例如X.509
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @param password 密码
|
||||
* @param alias 别名
|
||||
* @return {@link KeyStore}
|
||||
* @since 4.4.1
|
||||
*/
|
||||
public static Certificate readCertificate(final String type, final InputStream in, final char[] password, final String alias) {
|
||||
return KeyUtil.readCertificate(type, in, password, alias);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取Certification文件<br>
|
||||
* Certification为证书文件<br>
|
||||
* see: http://snowolf.iteye.com/blog/391931
|
||||
*
|
||||
* @param type 类型,例如X.509
|
||||
* @param in {@link InputStream} 如果想从文件读取.cer文件,使用 {@link FileUtil#getInputStream(java.io.File)} 读取
|
||||
* @return {@link Certificate}
|
||||
*/
|
||||
public static Certificate readCertificate(final String type, final InputStream in) {
|
||||
return KeyUtil.readCertificate(type, in);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得 Certification
|
||||
*
|
||||
* @param keyStore {@link KeyStore}
|
||||
* @param alias 别名
|
||||
* @return {@link Certificate}
|
||||
*/
|
||||
public static Certificate getCertificate(final KeyStore keyStore, final String alias) {
|
||||
return KeyUtil.getCertificate(keyStore, alias);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------- 对称加密算法
|
||||
|
||||
/**
|
||||
@@ -820,156 +485,6 @@ public class SecureUtil {
|
||||
return new RSA(privateKey, publicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建签名算法对象<br>
|
||||
* 生成新的私钥公钥对
|
||||
*
|
||||
* @param algorithm 签名算法
|
||||
* @return {@link Sign}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static Sign sign(final SignAlgorithm algorithm) {
|
||||
return SignUtil.sign(algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建签名算法对象<br>
|
||||
* 私钥和公钥同时为空时生成一对新的私钥和公钥<br>
|
||||
* 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做签名或验证
|
||||
*
|
||||
* @param algorithm 签名算法
|
||||
* @param privateKeyBase64 私钥Base64
|
||||
* @param publicKeyBase64 公钥Base64
|
||||
* @return {@link Sign}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static Sign sign(final SignAlgorithm algorithm, final String privateKeyBase64, final String publicKeyBase64) {
|
||||
return SignUtil.sign(algorithm, privateKeyBase64, publicKeyBase64);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建Sign算法对象<br>
|
||||
* 私钥和公钥同时为空时生成一对新的私钥和公钥<br>
|
||||
* 私钥和公钥可以单独传入一个,如此则只能使用此钥匙来做签名或验证
|
||||
*
|
||||
* @param algorithm 算法枚举
|
||||
* @param privateKey 私钥
|
||||
* @param publicKey 公钥
|
||||
* @return {@link Sign}
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static Sign sign(final SignAlgorithm algorithm, final byte[] privateKey, final byte[] publicKey) {
|
||||
return SignUtil.sign(algorithm, privateKey, publicKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串<br>
|
||||
* 拼接后的字符串键值对之间无符号,键值对之间无符号,忽略null值
|
||||
*
|
||||
* @param crypto 对称加密算法
|
||||
* @param params 参数
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParams(final SymmetricCrypto crypto, final Map<?, ?> params, final String... otherParams) {
|
||||
return SignUtil.signParams(crypto, params, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串
|
||||
*
|
||||
* @param crypto 对称加密算法
|
||||
* @param params 参数
|
||||
* @param separator entry之间的连接符
|
||||
* @param keyValueSeparator kv之间的连接符
|
||||
* @param isIgnoreNull 是否忽略null的键和值
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParams(final SymmetricCrypto crypto, final Map<?, ?> params, final String separator,
|
||||
final String keyValueSeparator, final boolean isIgnoreNull, final String... otherParams) {
|
||||
return SignUtil.signParams(crypto, params, separator, keyValueSeparator, isIgnoreNull, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做md5签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串<br>
|
||||
* 拼接后的字符串键值对之间无符号,键值对之间无符号,忽略null值
|
||||
*
|
||||
* @param params 参数
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParamsMd5(final Map<?, ?> params, final String... otherParams) {
|
||||
return SignUtil.signParamsMd5(params, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做Sha1签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串<br>
|
||||
* 拼接后的字符串键值对之间无符号,键值对之间无符号,忽略null值
|
||||
*
|
||||
* @param params 参数
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.8
|
||||
*/
|
||||
public static String signParamsSha1(final Map<?, ?> params, final String... otherParams) {
|
||||
return SignUtil.signParamsSha1(params, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做Sha256签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串<br>
|
||||
* 拼接后的字符串键值对之间无符号,键值对之间无符号,忽略null值
|
||||
*
|
||||
* @param params 参数
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParamsSha256(final Map<?, ?> params, final String... otherParams) {
|
||||
return SignUtil.signParamsSha256(params, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串<br>
|
||||
* 拼接后的字符串键值对之间无符号,键值对之间无符号,忽略null值
|
||||
*
|
||||
* @param digestAlgorithm 摘要算法
|
||||
* @param params 参数
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParams(final DigestAlgorithm digestAlgorithm, final Map<?, ?> params, final String... otherParams) {
|
||||
return SignUtil.signParams(digestAlgorithm, params, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对参数做签名<br>
|
||||
* 参数签名为对Map参数按照key的顺序排序后拼接为字符串,然后根据提供的签名算法生成签名字符串
|
||||
*
|
||||
* @param digestAlgorithm 摘要算法
|
||||
* @param params 参数
|
||||
* @param separator entry之间的连接符
|
||||
* @param keyValueSeparator kv之间的连接符
|
||||
* @param isIgnoreNull 是否忽略null的键和值
|
||||
* @param otherParams 其它附加参数字符串(例如密钥)
|
||||
* @return 签名
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static String signParams(final DigestAlgorithm digestAlgorithm, final Map<?, ?> params, final String separator,
|
||||
final String keyValueSeparator, final boolean isIgnoreNull, final String... otherParams) {
|
||||
return SignUtil.signParams(digestAlgorithm, params, separator, keyValueSeparator, isIgnoreNull, otherParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加加密解密的算法提供者,默认优先使用,例如:
|
||||
*
|
||||
@@ -1060,26 +575,6 @@ public class SecureUtil {
|
||||
return mac;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@link Signature}
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @return {@link Signature}
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public static Signature createSignature(final String algorithm) {
|
||||
final Provider provider = GlobalBouncyCastleProvider.INSTANCE.getProvider();
|
||||
|
||||
final Signature signature;
|
||||
try {
|
||||
signature = (null == provider) ? Signature.getInstance(algorithm) : Signature.getInstance(algorithm, provider);
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
throw new CryptoException(e);
|
||||
}
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* RC4算法
|
||||
*
|
||||
|
||||
@@ -2,12 +2,16 @@ package cn.hutool.crypto;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.AsymmetricAlgorithm;
|
||||
import cn.hutool.crypto.asymmetric.Sign;
|
||||
import cn.hutool.crypto.asymmetric.SignAlgorithm;
|
||||
import cn.hutool.crypto.digest.DigestAlgorithm;
|
||||
import cn.hutool.crypto.digest.Digester;
|
||||
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Provider;
|
||||
import java.security.Signature;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -24,6 +28,37 @@ import java.util.Map;
|
||||
*/
|
||||
public class SignUtil {
|
||||
|
||||
/**
|
||||
* 生成签名对象,仅用于非对称加密
|
||||
*
|
||||
* @param asymmetricAlgorithm {@link AsymmetricAlgorithm} 非对称加密算法
|
||||
* @param digestAlgorithm {@link DigestAlgorithm} 摘要算法
|
||||
* @return {@link Signature}
|
||||
*/
|
||||
public static Signature createSignature(final AsymmetricAlgorithm asymmetricAlgorithm, final DigestAlgorithm digestAlgorithm) {
|
||||
return createSignature(SecureUtil.generateAlgorithm(asymmetricAlgorithm, digestAlgorithm));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建{@link Signature}签名对象
|
||||
*
|
||||
* @param algorithm 算法
|
||||
* @return {@link Signature}
|
||||
* @since 5.7.0
|
||||
*/
|
||||
public static Signature createSignature(final String algorithm) {
|
||||
final Provider provider = GlobalBouncyCastleProvider.INSTANCE.getProvider();
|
||||
|
||||
final Signature signature;
|
||||
try {
|
||||
signature = (null == provider) ? Signature.getInstance(algorithm) : Signature.getInstance(algorithm, provider);
|
||||
} catch (final NoSuchAlgorithmException e) {
|
||||
throw new CryptoException(e);
|
||||
}
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建签名算法对象<br>
|
||||
* 生成新的私钥公钥对
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.hutool.crypto.asymmetric;
|
||||
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.GlobalBouncyCastleProvider;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
@@ -42,7 +42,7 @@ public class RSA extends AsymmetricCrypto {
|
||||
* @return {@link PrivateKey}
|
||||
*/
|
||||
public static PrivateKey generatePrivateKey(final BigInteger modulus, final BigInteger privateExponent) {
|
||||
return SecureUtil.generatePrivateKey(ALGORITHM_RSA.getValue(), new RSAPrivateKeySpec(modulus, privateExponent));
|
||||
return KeyUtil.generatePrivateKey(ALGORITHM_RSA.getValue(), new RSAPrivateKeySpec(modulus, privateExponent));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +53,7 @@ public class RSA extends AsymmetricCrypto {
|
||||
* @return {@link PublicKey}
|
||||
*/
|
||||
public static PublicKey generatePublicKey(final BigInteger modulus, final BigInteger publicExponent) {
|
||||
return SecureUtil.generatePublicKey(ALGORITHM_RSA.getValue(), new RSAPublicKeySpec(modulus, publicExponent));
|
||||
return KeyUtil.generatePublicKey(ALGORITHM_RSA.getValue(), new RSAPublicKeySpec(modulus, publicExponent));
|
||||
}
|
||||
// ------------------------------------------------------------------ Static method end
|
||||
|
||||
|
||||
@@ -7,7 +7,9 @@ import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import cn.hutool.crypto.SignUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
@@ -124,8 +126,8 @@ public class Sign extends BaseAsymmetric<Sign> {
|
||||
*/
|
||||
public Sign(final String algorithm, final byte[] privateKey, final byte[] publicKey) {
|
||||
this(algorithm, //
|
||||
SecureUtil.generatePrivateKey(algorithm, privateKey), //
|
||||
SecureUtil.generatePublicKey(algorithm, publicKey)//
|
||||
KeyUtil.generatePrivateKey(algorithm, privateKey), //
|
||||
KeyUtil.generatePublicKey(algorithm, publicKey)//
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,7 +167,7 @@ public class Sign extends BaseAsymmetric<Sign> {
|
||||
*/
|
||||
@Override
|
||||
public Sign init(final String algorithm, final PrivateKey privateKey, final PublicKey publicKey) {
|
||||
signature = SecureUtil.createSignature(algorithm);
|
||||
signature = SignUtil.createSignature(algorithm);
|
||||
super.init(algorithm, privateKey, publicKey);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.hutool.crypto.digest.mac;
|
||||
|
||||
import cn.hutool.crypto.CryptoException;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
@@ -94,7 +95,7 @@ public class DefaultHMacEngine implements MacEngine {
|
||||
try {
|
||||
mac = SecureUtil.createMac(algorithm);
|
||||
if (null == key) {
|
||||
key = SecureUtil.generateKey(algorithm);
|
||||
key = KeyUtil.generateKey(algorithm);
|
||||
}
|
||||
if (null != spec) {
|
||||
mac.init(key, spec);
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
/**
|
||||
* DES加密算法实现<br>
|
||||
* DES全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法<br>
|
||||
@@ -113,7 +113,7 @@ public class DES extends SymmetricCrypto {
|
||||
* @param key 密钥,长度:8的倍数
|
||||
*/
|
||||
public DES(final String mode, final String padding, final byte[] key) {
|
||||
this(mode, padding, SecureUtil.generateKey("DES", key), null);
|
||||
this(mode, padding, KeyUtil.generateKey("DES", key), null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,7 +125,7 @@ public class DES extends SymmetricCrypto {
|
||||
* @param iv 加盐
|
||||
*/
|
||||
public DES(final String mode, final String padding, final byte[] key, final byte[] iv) {
|
||||
this(mode, padding, SecureUtil.generateKey("DES", key), null == iv ? null : new IvParameterSpec(iv));
|
||||
this(mode, padding, KeyUtil.generateKey("DES", key), null == iv ? null : new IvParameterSpec(iv));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
/**
|
||||
* DESede是由DES对称加密算法改进后的一种对称加密算法,又名3DES、TripleDES。<br>
|
||||
* 使用 168 位的密钥对资料进行三次加密的一种机制;它通常(但非始终)提供极其强大的安全性。<br>
|
||||
@@ -126,7 +126,7 @@ public class DESede extends SymmetricCrypto {
|
||||
* @param iv 加盐
|
||||
*/
|
||||
public DESede(final String mode, final String padding, final byte[] key, final byte[] iv) {
|
||||
this(mode, padding, SecureUtil.generateKey(SymmetricAlgorithm.DESede.getValue(), key), null == iv ? null : new IvParameterSpec(iv));
|
||||
this(mode, padding, KeyUtil.generateKey(SymmetricAlgorithm.DESede.getValue(), key), null == iv ? null : new IvParameterSpec(iv));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package cn.hutool.crypto.symmetric;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.crypto.KeyUtil;
|
||||
import cn.hutool.crypto.Mode;
|
||||
import cn.hutool.crypto.Padding;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
@@ -144,7 +144,7 @@ public class SM4 extends SymmetricCrypto{
|
||||
*/
|
||||
public SM4(final String mode, final String padding, final byte[] key, final byte[] iv) {
|
||||
this(mode, padding,//
|
||||
SecureUtil.generateKey(ALGORITHM_NAME, key),//
|
||||
KeyUtil.generateKey(ALGORITHM_NAME, key),//
|
||||
ArrayUtil.isEmpty(iv) ? null : new IvParameterSpec(iv));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user