mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix test
This commit is contained in:
parent
73507e7799
commit
2c2c7bba6a
@ -46,4 +46,16 @@ public class KeyUtilTest {
|
||||
final PrivateKey privateKey = KeyUtil.generatePrivateKey("EC", privateKeyBytes);
|
||||
Assert.assertEquals(ecies.getPrivate(), privateKey);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDHTest(){
|
||||
final KeyPair dh = KeyUtil.generateKeyPair("DH");
|
||||
Assert.assertNotNull(dh.getPrivate());
|
||||
Assert.assertNotNull(dh.getPublic());
|
||||
|
||||
byte[] privateKeyBytes = dh.getPrivate().getEncoded();
|
||||
|
||||
final PrivateKey privateKey = KeyUtil.generatePrivateKey("DH", privateKeyBytes);
|
||||
Assert.assertEquals(dh.getPrivate(), privateKey);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,18 @@
|
||||
package cn.hutool.crypto.test.asymmetric;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.HexUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.ASN1Util;
|
||||
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.asn1.ASN1Integer;
|
||||
import org.bouncycastle.asn1.ASN1Sequence;
|
||||
import org.bouncycastle.crypto.engines.SM2Engine;
|
||||
import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
|
||||
import org.bouncycastle.jcajce.spec.OpenSSHPrivateKeySpec;
|
||||
import org.bouncycastle.math.ec.ECPoint;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -316,14 +311,4 @@ public class SM2Test {
|
||||
byte[] dec = sm2.decrypt(data, KeyType.PrivateKey);
|
||||
Assert.assertArrayEquals(dec, src.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void asn1DecryptTest(){
|
||||
final SM2 sm2 = SmUtil.sm2("00dc7651c8473110a83215bfd26f37e306b2b99b02da9a4af9b9bd12e6360849bd", null);
|
||||
final ASN1Sequence asn1 = (ASN1Sequence) ASN1Util.decode(ResourceUtil.getStream("asn1.key"));
|
||||
|
||||
ASN1Integer x = (ASN1Integer) asn1.getObjectAt(0);
|
||||
ASN1Integer y = (ASN1Integer) asn1.getObjectAt(1);
|
||||
final ECPoint point = SmUtil.SM2_DOMAIN_PARAMS.getCurve().createPoint(x.getValue(), y.getValue());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user