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);
}
Aggregations