mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
fix code
This commit is contained in:
@@ -781,16 +781,18 @@ public class SM2 extends AbstractAsymmetricCrypto<SM2> {
|
||||
* @return {@link CipherParameters}
|
||||
*/
|
||||
private CipherParameters getCipherParameters(final KeyType keyType) {
|
||||
switch (keyType) {
|
||||
case PublicKey:
|
||||
return switch (keyType) {
|
||||
case PublicKey -> {
|
||||
Assert.notNull(this.publicKeyParams, "PublicKey must be not null !");
|
||||
return this.publicKeyParams;
|
||||
case PrivateKey:
|
||||
yield this.publicKeyParams;
|
||||
}
|
||||
case PrivateKey -> {
|
||||
Assert.notNull(this.privateKeyParams, "PrivateKey must be not null !");
|
||||
return this.privateKeyParams;
|
||||
}
|
||||
yield this.privateKeyParams;
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -221,7 +221,7 @@ public class Sign extends BaseAsymmetric<Sign> {
|
||||
if (CollUtil.isNotEmpty(critSet) && critSet.contains("2.5.29.15")) {
|
||||
final boolean[] keyUsageInfo = cert.getKeyUsage();
|
||||
// keyUsageInfo[0] is for digitalSignature.
|
||||
if ((keyUsageInfo != null) && (keyUsageInfo[0] == false)) {
|
||||
if ((keyUsageInfo != null) && (!keyUsageInfo[0])) {
|
||||
throw new CryptoException("Wrong key usage");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,20 +69,12 @@ public class ASN1Util {
|
||||
* @param elements ASN.1元素
|
||||
*/
|
||||
public static void encodeTo(final String asn1Encoding, final OutputStream out, final ASN1Encodable... elements) {
|
||||
final ASN1Sequence sequence;
|
||||
switch (asn1Encoding) {
|
||||
case ASN1Encoding.DER:
|
||||
sequence = new DERSequence(elements);
|
||||
break;
|
||||
case ASN1Encoding.BER:
|
||||
sequence = new BERSequence(elements);
|
||||
break;
|
||||
case ASN1Encoding.DL:
|
||||
sequence = new DLSequence(elements);
|
||||
break;
|
||||
default:
|
||||
throw new CryptoException("Unsupported ASN1 encoding: {}", asn1Encoding);
|
||||
}
|
||||
final ASN1Sequence sequence = switch (asn1Encoding) {
|
||||
case ASN1Encoding.DER -> new DERSequence(elements);
|
||||
case ASN1Encoding.BER -> new BERSequence(elements);
|
||||
case ASN1Encoding.DL -> new DLSequence(elements);
|
||||
default -> throw new CryptoException("Unsupported ASN1 encoding: {}", asn1Encoding);
|
||||
};
|
||||
try {
|
||||
sequence.encodeTo(out);
|
||||
} catch (final IOException e) {
|
||||
|
||||
@@ -146,17 +146,13 @@ public class BCUtil {
|
||||
return new CTSBlockCipher(cipher);
|
||||
}
|
||||
|
||||
switch (padding) {
|
||||
case NoPadding:
|
||||
return new DefaultBufferedBlockCipher(cipher);
|
||||
case PKCS5Padding:
|
||||
return new PaddedBufferedBlockCipher(cipher);
|
||||
case ZeroPadding:
|
||||
return new PaddedBufferedBlockCipher(cipher, new ZeroBytePadding());
|
||||
case ISO10126Padding:
|
||||
return new PaddedBufferedBlockCipher(cipher, new ISO10126d2Padding());
|
||||
}
|
||||
return switch (padding) {
|
||||
case NoPadding -> new DefaultBufferedBlockCipher(cipher);
|
||||
case PKCS5Padding -> new PaddedBufferedBlockCipher(cipher);
|
||||
case ZeroPadding -> new PaddedBufferedBlockCipher(cipher, new ZeroBytePadding());
|
||||
case ISO10126Padding -> new PaddedBufferedBlockCipher(cipher, new ISO10126d2Padding());
|
||||
default -> null;
|
||||
};
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,9 +56,7 @@ public class ECIESTest {
|
||||
private void doTest(final AsymmetricCrypto cryptoForEncrypt, final AsymmetricCrypto cryptoForDecrypt){
|
||||
final String textBase = "我是一段特别长的测试";
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
text.append(textBase);
|
||||
}
|
||||
text.append(textBase.repeat(10));
|
||||
|
||||
// 公钥加密,私钥解密
|
||||
final String encryptStr = cryptoForEncrypt.encryptBase64(text.toString(), KeyType.PublicKey);
|
||||
|
||||
@@ -161,9 +161,7 @@ public class RSATest {
|
||||
public void rsaBase64Test() {
|
||||
final String textBase = "我是一段特别长的测试";
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
text.append(textBase);
|
||||
}
|
||||
text.append(textBase.repeat(10));
|
||||
|
||||
final RSA rsa = new RSA();
|
||||
|
||||
|
||||
@@ -100,9 +100,7 @@ public class SM2Test {
|
||||
public void sm2Base64Test() {
|
||||
final String textBase = "我是一段特别长的测试";
|
||||
final StringBuilder text = new StringBuilder();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
text.append(textBase);
|
||||
}
|
||||
text.append(textBase.repeat(100));
|
||||
|
||||
SM2 sm2 = new SM2();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user