use of com.github.zhenwei.sdk.builder.CipherBuilder in project LinLong-Java by zhenwei1108.
the class CipherTest method encDecDataTest.
@Test
public void encDecDataTest() throws BaseWeGooException {
WeGooProvider provider = new WeGooProvider();
CipherBuilder builder = new CipherBuilder(provider);
KeyBuilder keyBuilder = new KeyBuilder(provider);
// SM2加解密
KeyPair keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.SM2_256);
byte[] data = "this is my encrypt data test".getBytes(StandardCharsets.UTF_8);
IvParameterSpec spec = new IvParameterSpec(new byte[16]);
byte[] encryptedData = builder.cipher(CipherAlgEnum.SM2, keyPair.getPublic(), data, spec, true);
data = builder.cipher(CipherAlgEnum.SM2, keyPair.getPrivate(), encryptedData, spec, false);
System.out.println("解密结果: " + new String(data));
// RSA加解密
keyPair = keyBuilder.buildKeyPair(KeyPairAlgEnum.RSA_2048);
encryptedData = builder.cipher(CipherAlgEnum.RSA, keyPair.getPublic(), data, spec, true);
data = builder.cipher(CipherAlgEnum.RSA, keyPair.getPrivate(), encryptedData, spec, false);
System.out.println("解密结果: " + new String(data));
}
Aggregations