Search in sources :

Example 16 with WeGooProvider

use of com.github.zhenwei.provider.jce.provider.WeGooProvider 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)

Example 17 with WeGooProvider

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

Example 18 with WeGooProvider

use of com.github.zhenwei.provider.jce.provider.WeGooProvider in project LinLong-Java by zhenwei1108.

the class RealSignerTest method readSigner.

@Test
public void readSigner() throws BaseWeGooException {
    WeGooProvider weGooProvider = new WeGooProvider();
    SignBuilder signBuilder = new SignBuilder(weGooProvider);
    KeyBuilder keyBuilder = new KeyBuilder(weGooProvider);
    KeyPair keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.RSA_1024);
    byte[] data = signBuilder.signatureSourceData(SignAlgEnum.SHA256_WITH_RSA, keyPair.getPrivate(), "asdfa".getBytes(StandardCharsets.UTF_8));
    System.out.println(Hex.toHexString(data));
}
Also used : KeyBuilder(com.github.zhenwei.sdk.builder.KeyBuilder) KeyPair(java.security.KeyPair) SignBuilder(com.github.zhenwei.sdk.builder.SignBuilder) WeGooProvider(com.github.zhenwei.provider.jce.provider.WeGooProvider) Test(org.junit.Test)

Aggregations

WeGooProvider (com.github.zhenwei.provider.jce.provider.WeGooProvider)18 KeyBuilder (com.github.zhenwei.sdk.builder.KeyBuilder)11 Test (org.junit.Test)10 KeyPair (java.security.KeyPair)6 WeGooCryptoException (com.github.zhenwei.core.exception.WeGooCryptoException)4 BCRSAPublicKey (com.github.zhenwei.provider.jcajce.provider.asymmetric.rsa.BCRSAPublicKey)3 PrivateKeyInfo (com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)2 KeyPairAlgEnum (com.github.zhenwei.core.enums.KeyPairAlgEnum)2 BaseWeGooException (com.github.zhenwei.core.exception.BaseWeGooException)2 WeGooKeyException (com.github.zhenwei.core.exception.WeGooKeyException)2 P10Builder (com.github.zhenwei.sdk.builder.P10Builder)2 SignBuilder (com.github.zhenwei.sdk.builder.SignBuilder)2 KeyStore (java.security.KeyStore)2 PKCS8EncodedKeySpec (java.security.spec.PKCS8EncodedKeySpec)2 X500Name (com.github.zhenwei.core.asn1.x500.X500Name)1 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)1 SubjectPublicKeyInfo (com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo)1 CertBuilder (com.github.zhenwei.sdk.builder.CertBuilder)1 CipherBuilder (com.github.zhenwei.sdk.builder.CipherBuilder)1 HashBuilder (com.github.zhenwei.sdk.builder.HashBuilder)1