use of org.fisco.bcos.channel.client.P12Manager 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);
}
use of org.fisco.bcos.channel.client.P12Manager 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.channel.client.P12Manager in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method verifySecp256ECDSASignTest0.
@Test
public void verifySecp256ECDSASignTest0() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-keystore-sample.xml");
// test p12
P12Manager p12 = context.getBean(P12Manager.class);
ECKeyPair ecKeyPair = p12.getECKeyPair();
ECDSASign ecdsaSign = new ECDSASign();
String message = "message";
Sign.SignatureData signatureData = ecdsaSign.secp256SignMessage(message.getBytes(), ecKeyPair);
SHA3Digest sha3Digest = new SHA3Digest();
byte[] hash = sha3Digest.hash(message.getBytes());
boolean verify = ecdsaSign.secp256Verify(hash, ecKeyPair.getPublicKey(), signatureData);
assertEquals(verify, true);
}
use of org.fisco.bcos.channel.client.P12Manager in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method verifyECDSASignTest0.
@Test
public void verifyECDSASignTest0() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-keystore-sample.xml");
// test p12
P12Manager p12 = context.getBean(P12Manager.class);
ECKeyPair ecKeyPair = p12.getECKeyPair();
ECDSASign ecdsaSign = new ECDSASign();
String message = "message";
Sign.SignatureData signatureData = ecdsaSign.signMessage(message.getBytes(), ecKeyPair);
SHA3Digest sha3Digest = new SHA3Digest();
byte[] hash = sha3Digest.hash(message.getBytes());
boolean verify = ecdsaSign.verify(hash, ecKeyPair.getPublicKey(), signatureData);
assertEquals(verify, true);
}
use of org.fisco.bcos.channel.client.P12Manager in project web3sdk by FISCO-BCOS.
the class ECKeyPairTest method verifyECKeyPairTestWithPem.
@Test
public void verifyECKeyPairTestWithPem() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext-keystore-sample.xml");
// test p12
P12Manager p12 = context.getBean(P12Manager.class);
ECKeyPair ecKeyPair = p12.getECKeyPair();
String message = "ecc encrypt test";
ECDSASignature signature = ecKeyPair.sign(message.getBytes());
boolean verify = ecKeyPair.verify(message.getBytes(), signature);
assertEquals(verify, true);
}
Aggregations