use of org.fisco.bcos.web3j.crypto.tool.ECCDecrypt in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method encryptECKeyPairTestWithPem.
@Test
public void encryptECKeyPairTestWithPem() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-keystore-sample.xml");
// test p12
P12Manager p12 = context.getBean(P12Manager.class);
ECKeyPair ecKeyPair = p12.getECKeyPair();
ECCEncrypt encrypt = new ECCEncrypt(ecKeyPair.getPublicKey());
ECCDecrypt decrypt = new ECCDecrypt(ecKeyPair.getPrivateKey());
String message = "";
byte[] encryptData = encrypt.encrypt(message.getBytes("utf-8"));
byte[] decryptData = decrypt.decrypt(encryptData);
assertEquals(message, new String(decryptData, "utf-8"));
}
use of org.fisco.bcos.web3j.crypto.tool.ECCDecrypt in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method encryptECKeyPairTest.
@Test
public void encryptECKeyPairTest() throws Exception {
ECKeyPair ecKeyPair = Keys.createEcKeyPair();
ECCEncrypt encrypt = new ECCEncrypt(ecKeyPair.getPublicKey());
ECCDecrypt decrypt = new ECCDecrypt(ecKeyPair.getPrivateKey());
String message = "ecc encrypt test";
byte[] encryptData = encrypt.encrypt(message.getBytes("utf-8"));
byte[] decryptData = decrypt.decrypt(encryptData);
String decrpptMessage = new String(decryptData, "utf-8");
assertEquals(message, decrpptMessage);
}
use of org.fisco.bcos.web3j.crypto.tool.ECCDecrypt in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method encryptECKeyPairTestEmptyString.
@Test
public void encryptECKeyPairTestEmptyString() throws Exception {
Credentials credentials = GenCredential.create();
ECKeyPair ecKeyPair = credentials.getEcKeyPair();
ECCEncrypt encrypt = new ECCEncrypt(ecKeyPair.getPublicKey());
ECCDecrypt decrypt = new ECCDecrypt(ecKeyPair.getPrivateKey());
String message = "";
byte[] encryptData = encrypt.encrypt(message.getBytes("utf-8"));
byte[] decryptData = decrypt.decrypt(encryptData);
assertEquals(message, new String(decryptData, "utf-8"));
}
Aggregations