Search in sources :

Example 1 with PEMManager

use of org.fisco.bcos.channel.client.PEMManager in project web3sdk by FISCO-BCOS.

the class AccountTest method accountTest.

@Test
public void accountTest() throws UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-keystore-sample.xml");
    // test p12
    P12Manager p12 = context.getBean(P12Manager.class);
    ECKeyPair p12KeyPair = p12.getECKeyPair();
    assertEquals(p12KeyPair.getPrivateKey().toString(16), PRIVATE_KEY);
    assertEquals(p12KeyPair.getPublicKey().toString(16), PUBLIC_KEY);
    ECPublicKey publicKey = (ECPublicKey) p12.getPublicKey();
    byte[] publicKeyBytes = publicKey.getQ().getEncoded(false);
    BigInteger publicKeyValue = new BigInteger(1, Arrays.copyOfRange(publicKeyBytes, 1, publicKeyBytes.length));
    assertEquals(publicKeyValue.toString(16), PUBLIC_KEY);
    Credentials credentials = Credentials.create(p12KeyPair);
    assertEquals(credentials.getAddress(), ADDRESS);
    // test pem
    PEMManager pem = context.getBean(PEMManager.class);
    ECKeyPair pemKeyPair = pem.getECKeyPair();
    assertEquals(pemKeyPair.getPrivateKey().toString(16), PRIVATE_KEY);
    assertEquals(pemKeyPair.getPublicKey().toString(16), PUBLIC_KEY);
    Credentials credentialsPEM = Credentials.create(pemKeyPair);
    assertEquals(credentialsPEM.getAddress(), ADDRESS);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ECPublicKey(org.bouncycastle.jce.interfaces.ECPublicKey) PEMManager(org.fisco.bcos.channel.client.PEMManager) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) P12Manager(org.fisco.bcos.channel.client.P12Manager) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) BigInteger(java.math.BigInteger) Credentials(org.fisco.bcos.web3j.crypto.Credentials) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)1 ECPublicKey (org.bouncycastle.jce.interfaces.ECPublicKey)1 P12Manager (org.fisco.bcos.channel.client.P12Manager)1 PEMManager (org.fisco.bcos.channel.client.PEMManager)1 Credentials (org.fisco.bcos.web3j.crypto.Credentials)1 ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)1 Test (org.junit.Test)1 ApplicationContext (org.springframework.context.ApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1