use of com.github.zhenwei.sdk.builder.KeyBuilder in project LinLong-Java by zhenwei1108.
the class KeyPairTest method covertKeyPair.
@Test
public void covertKeyPair() throws Exception {
KeyBuilder builder = new KeyBuilder(new WeGooProvider());
KeyPair keyPair = builder.buildKeyPair(KeyPairAlgEnum.SM2_256);
System.out.println("公钥:" + Hex.toHexString(keyPair.getPublic().getEncoded()));
System.out.println("私钥:" + Hex.toHexString(keyPair.getPrivate().getEncoded()));
PublicKey publicKey = builder.convertPublicKey(keyPair.getPublic().getEncoded());
PrivateKey privateKey = builder.convertPrivateKey(keyPair.getPrivate().getEncoded());
System.out.println("公钥:" + Hex.toHexString(publicKey.getEncoded()));
System.out.println("私钥:" + Hex.toHexString(privateKey.getEncoded()));
}
use of com.github.zhenwei.sdk.builder.KeyBuilder in project LinLong-Java by zhenwei1108.
the class KeyPairTest method genRsa1024Key.
@Test
public void genRsa1024Key() throws BaseWeGooException {
KeyBuilder builder = new KeyBuilder(new WeGooProvider());
KeyPair keyPair = builder.buildKeyPair(KeyPairAlgEnum.RSA_1024);
System.out.println(Base64Util.encode(keyPair.getPrivate().getEncoded()));
System.out.println(Base64Util.encode(keyPair.getPublic().getEncoded()));
BCRSAPublicKey aPublic = (BCRSAPublicKey) keyPair.getPublic();
// 大素数
System.out.println("modulus:" + aPublic.getModulus().toString());
BigInteger mod = aPublic.getModulus().mod(BigInteger.valueOf(128));
System.out.println(mod);
// 指数
System.out.println("exponent:" + aPublic.getPublicExponent().intValue());
}
use of com.github.zhenwei.sdk.builder.KeyBuilder in project LinLong-Java by zhenwei1108.
the class KeyStoreTest method genJks.
@Test
public void genJks() throws Exception {
KeyStoreBuilder builder = new KeyStoreBuilder();
KeyBuilder keyBuilder = new KeyBuilder(new WeGooProvider());
KeyPair keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.SM2_256);
P10Builder p10Builder = new P10Builder("C=CN,CN=demo,O=zhenwei", keyPair.getPublic(), keyPair.getPrivate(), null);
byte[] certificate = CertBuilder.generateCertificate("C=CN,CN=demo,O=zhenwei", "C=CN,CN=demo", keyPair.getPublic(), keyPair.getPrivate());
System.out.println("证书:" + Base64Util.encode(certificate));
System.out.println(Hex.toHexString(keyPair.getPrivate().getEncoded()));
X509Certificate cert = CertBuilder.getInstance(certificate).getCert();
byte[] jks = builder.genJks(keyPair.getPrivate(), "test", "123123", new Certificate[] { cert });
System.out.println(Hex.toHexString(jks));
}
use of com.github.zhenwei.sdk.builder.KeyBuilder in project LinLong-Java by zhenwei1108.
the class P10Test method genP10.
@Test
public void genP10() throws Exception {
WeGooProvider provider = new WeGooProvider();
KeyBuilder keyBuilder = new KeyBuilder(provider);
KeyPair keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.SM2_256);
List<CertExtension> list = new ArrayList<>();
CertExtension certExtension = new CertExtension("1.2.3", "demo1111".getBytes(StandardCharsets.UTF_8), CodingType.DEROCTETSTRING);
list.add(certExtension);
P10Builder p10Builder = new P10Builder("C=CN,CN=TEST", keyPair.getPublic(), keyPair.getPrivate(), list);
String p10 = p10Builder.getP10();
System.out.println(p10);
}
use of com.github.zhenwei.sdk.builder.KeyBuilder in project LinLong-Java by zhenwei1108.
the class RealHashTest method sm3Digest.
@Test
public void sm3Digest() throws BaseWeGooException {
WeGooProvider provider = new WeGooProvider();
HashBuilder builder = new HashBuilder(provider);
byte[] source = "asdf".getBytes(StandardCharsets.UTF_8);
byte[] digest = builder.digest(DigestAlgEnum.SM3, source);
System.out.println(Hex.toHexString(digest));
// 公钥参与运算
KeyBuilder keyBuilder = new KeyBuilder(provider);
KeyPair keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.SM2_256);
DigestParams digestParams = new DigestParams(keyPair.getPublic());
digest = builder.digest(DigestAlgEnum.SM3, source, digestParams);
System.out.println(Hex.toHexString(digest));
}
Aggregations