Search in sources :

Example 1 with P10Builder

use of com.github.zhenwei.sdk.builder.P10Builder 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));
}
Also used : KeyBuilder(com.github.zhenwei.sdk.builder.KeyBuilder) KeyPair(java.security.KeyPair) WeGooProvider(com.github.zhenwei.provider.jce.provider.WeGooProvider) KeyStoreBuilder(com.github.zhenwei.sdk.builder.KeyStoreBuilder) P10Builder(com.github.zhenwei.sdk.builder.P10Builder) X509Certificate(java.security.cert.X509Certificate) Test(org.junit.Test)

Example 2 with P10Builder

use of com.github.zhenwei.sdk.builder.P10Builder 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);
}
Also used : KeyBuilder(com.github.zhenwei.sdk.builder.KeyBuilder) KeyPair(java.security.KeyPair) CertExtension(com.github.zhenwei.sdk.builder.params.CertExtension) WeGooProvider(com.github.zhenwei.provider.jce.provider.WeGooProvider) ArrayList(java.util.ArrayList) P10Builder(com.github.zhenwei.sdk.builder.P10Builder) Test(org.junit.Test)

Aggregations

WeGooProvider (com.github.zhenwei.provider.jce.provider.WeGooProvider)2 KeyBuilder (com.github.zhenwei.sdk.builder.KeyBuilder)2 P10Builder (com.github.zhenwei.sdk.builder.P10Builder)2 KeyPair (java.security.KeyPair)2 Test (org.junit.Test)2 KeyStoreBuilder (com.github.zhenwei.sdk.builder.KeyStoreBuilder)1 CertExtension (com.github.zhenwei.sdk.builder.params.CertExtension)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1