This commit is contained in:
Looly
2020-04-11 13:08:46 +08:00
parent 73fd3b849f
commit bc486cdac4
207 changed files with 1329 additions and 1355 deletions

View File

@@ -33,7 +33,7 @@ public enum SignAlgorithm {
SHA384withECDSA("SHA384withECDSA"), //
SHA512withECDSA("SHA512withECDSA");//
private String value;
private final String value;
/**
* 构造

View File

@@ -1,9 +1,9 @@
package cn.hutool.crypto.digest;
import java.security.SecureRandom;
import cn.hutool.core.util.CharsetUtil;
import java.security.SecureRandom;
/**
* BCrypt加密算法实现。由它加密的文件可在所有支持的操作系统和处理器上进行转移。它的口令必须是8至56个字符并将在内部被转化为448位的密钥。
* <p>
@@ -177,7 +177,7 @@ public class BCrypt {
* @return the decoded value of x
*/
private static byte char64(char x) {
if ((int) x < 0 || (int) x > index_64.length)
if ((int) x > index_64.length)
return -1;
return index_64[(int) x];
}
@@ -191,6 +191,7 @@ public class BCrypt {
* @return an array containing the decoded bytes
* @throws IllegalArgumentException if maxolen is invalid
*/
@SuppressWarnings("SameParameterValue")
private static byte[] decodeBase64(String s, int maxolen) throws IllegalArgumentException {
final StringBuilder rs = new StringBuilder();
int off = 0, slen = s.length(), olen = 0;
@@ -285,8 +286,8 @@ public class BCrypt {
* Initialise the Blowfish key schedule
*/
private void init_key() {
P = (int[]) P_orig.clone();
S = (int[]) S_orig.clone();
P = P_orig.clone();
S = S_orig.clone();
}
/**
@@ -438,7 +439,7 @@ public class BCrypt {
saltb = decodeBase64(real_salt, BCRYPT_SALT_LEN);
bcrypt = new BCrypt();
hashed = bcrypt.crypt(passwordb, saltb, rounds, (int[]) bf_crypt_ciphertext.clone());
hashed = bcrypt.crypt(passwordb, saltb, rounds, bf_crypt_ciphertext.clone());
rs.append("$2");
if (minor >= 'a')

View File

@@ -14,7 +14,7 @@ public enum DigestAlgorithm {
SHA384("SHA-384"),
SHA512("SHA-512");
private String value;
private final String value;
/**
* 构造

View File

@@ -1,13 +1,5 @@
package cn.hutool.crypto.digest;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.CharsetUtil;
@@ -17,6 +9,13 @@ import cn.hutool.crypto.CryptoException;
import cn.hutool.crypto.digest.mac.MacEngine;
import cn.hutool.crypto.digest.mac.MacEngineFactory;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.Serializable;
/**
* HMAC摘要算法<br>
* HMAC全称为“Hash Message Authentication Code”中文名“散列消息鉴别码”<br>
@@ -30,7 +29,7 @@ import cn.hutool.crypto.digest.mac.MacEngineFactory;
public class HMac implements Serializable {
private static final long serialVersionUID = 1L;
private MacEngine engine;
private final MacEngine engine;
// ------------------------------------------------------------------------------------------- Constructor start
/**

View File

@@ -15,7 +15,7 @@ public enum HmacAlgorithm {
/** HmacSM3算法实现需要BouncyCastle库支持 */
HmacSM3("HmacSM3");
private String value;
private final String value;
HmacAlgorithm(String value) {
this.value = value;

View File

@@ -22,7 +22,7 @@ public enum SymmetricAlgorithm {
PBEWithSHA1AndDESede("PBEWithSHA1AndDESede"),
PBEWithSHA1AndRC2_40("PBEWithSHA1AndRC2_40");
private String value;
private final String value;
/**
* 构造

View File

@@ -48,7 +48,7 @@ public class SymmetricCrypto implements Serializable {
* 是否0填充
*/
private boolean isZeroPadding;
private Lock lock = new ReentrantLock();
private final Lock lock = new ReentrantLock();
// ------------------------------------------------------------------ Constructor start

View File

@@ -8,11 +8,6 @@ import org.junit.Test;
public class BCUtilTest {
@Test
public void decodeECPointTest(){
}
/**
* 密钥生成来自https://i.goto327.top/CryptTools/SM2.aspx?tdsourcetag=s_pctim_aiomsg
*/