This commit is contained in:
Looly
2023-05-19 22:28:39 +08:00
parent 586b29f3d1
commit ea1c49a93b
23 changed files with 53 additions and 41 deletions

View File

@@ -174,7 +174,7 @@ public class KeyUtil {
}
if (null == password) {
password = RandomUtil.randomString(32).toCharArray();
password = RandomUtil.randomStringLower(32).toCharArray();
}
return generateKey(algorithm, SpecUtil.createPBEKeySpec(password));
}

View File

@@ -72,7 +72,7 @@ public class SpecUtil {
*/
public static PBEKeySpec createPBEKeySpec(char[] password) {
if (null == password) {
password = RandomUtil.randomString(32).toCharArray();
password = RandomUtil.randomStringLower(32).toCharArray();
}
return new PBEKeySpec(password);
}

View File

@@ -193,7 +193,7 @@ public class RSATest {
final byte[] keyBytes = Base64.decode(publicKeyStr);
final PublicKey publicKey = KeyUtil.generateRSAPublicKey(keyBytes);
final byte[] data = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 16).getBytes();
final byte[] data = RandomUtil.randomStringLower("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 16).getBytes();
//长度不满足128补0
final byte[] finalData = ArrayUtil.resize(data, 128);

View File

@@ -134,7 +134,7 @@ public class SymmetricTest {
@Test
public void aesZeroPaddingTest() {
final String content = RandomUtil.randomString(RandomUtil.randomInt(200));
final String content = RandomUtil.randomStringLower(RandomUtil.randomInt(200));
final AES aes = new AES(Mode.CBC, Padding.ZeroPadding, "0123456789ABHAEQ".getBytes(), "DYgjCEIMVrj2W9xN".getBytes());
// 加密为16进制表示
@@ -160,7 +160,7 @@ public class SymmetricTest {
@Test
public void aesPkcs7PaddingTest() {
final String content = RandomUtil.randomString(RandomUtil.randomInt(200));
final String content = RandomUtil.randomStringLower(RandomUtil.randomInt(200));
final AES aes = new AES("CBC", "PKCS7Padding",
RandomUtil.randomBytes(32),
"DYgjCEIMVrj2W9xN".getBytes());

View File

@@ -13,7 +13,7 @@ public class ZucTest {
final byte[] iv = RandomUtil.randomBytes(16);
final ZUC zuc = new ZUC(ZUC.ZUCAlgorithm.ZUC_128, secretKey, iv);
final String msg = RandomUtil.randomString(500);
final String msg = RandomUtil.randomStringLower(500);
final byte[] crypt2 = zuc.encrypt(msg);
final String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8);
Assertions.assertEquals(msg, msg2);
@@ -25,7 +25,7 @@ public class ZucTest {
final byte[] iv = RandomUtil.randomBytes(25);
final ZUC zuc = new ZUC(ZUC.ZUCAlgorithm.ZUC_256, secretKey, iv);
final String msg = RandomUtil.randomString(500);
final String msg = RandomUtil.randomStringLower(500);
final byte[] crypt2 = zuc.encrypt(msg);
final String msg2 = zuc.decryptStr(crypt2, CharsetUtil.UTF_8);
Assertions.assertEquals(msg, msg2);

View File

@@ -18,7 +18,7 @@ public class FPETest {
final FPE fpe = new FPE(FPE.FPEMode.FF1, keyBytes, numberMapper, null);
// 原始数据
final String phone = RandomUtil.randomString("A0123456789", 13);
final String phone = RandomUtil.randomStringLower("A0123456789", 13);
final String encrypt = fpe.encrypt(phone);
// 加密后与原密文长度一致
Assertions.assertEquals(phone.length(), encrypt.length());
@@ -37,7 +37,7 @@ public class FPETest {
final FPE fpe = new FPE(FPE.FPEMode.FF3_1, keyBytes, numberMapper, null);
// 原始数据
final String phone = RandomUtil.randomString("A0123456789", 13);
final String phone = RandomUtil.randomStringLower("A0123456789", 13);
final String encrypt = fpe.encrypt(phone);
// 加密后与原密文长度一致
Assertions.assertEquals(phone.length(), encrypt.length());