Search in sources :

Example 1 with ECCDecrypt

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"));
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) P12Manager(org.fisco.bcos.channel.client.P12Manager) ECCDecrypt(org.fisco.bcos.web3j.crypto.tool.ECCDecrypt) ECCEncrypt(org.fisco.bcos.web3j.crypto.tool.ECCEncrypt) Test(org.junit.Test)

Example 2 with ECCDecrypt

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);
}
Also used : ECCDecrypt(org.fisco.bcos.web3j.crypto.tool.ECCDecrypt) ECCEncrypt(org.fisco.bcos.web3j.crypto.tool.ECCEncrypt) Test(org.junit.Test)

Example 3 with ECCDecrypt

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"));
}
Also used : ECCDecrypt(org.fisco.bcos.web3j.crypto.tool.ECCDecrypt) ECCEncrypt(org.fisco.bcos.web3j.crypto.tool.ECCEncrypt) Test(org.junit.Test)

Aggregations

ECCDecrypt (org.fisco.bcos.web3j.crypto.tool.ECCDecrypt)3 ECCEncrypt (org.fisco.bcos.web3j.crypto.tool.ECCEncrypt)3 Test (org.junit.Test)3 P12Manager (org.fisco.bcos.channel.client.P12Manager)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1