Java Code Examples for org.fisco.bcos.web3j.crypto.Credentials#getAddress()
The following examples show how to use
org.fisco.bcos.web3j.crypto.Credentials#getAddress() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SignDataTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * key pair from sign differs from local credential * front or sign change @param encryptType: 1 and 0 to switch from guomi and standard */ @Test public void testKeyFromSign() { KeyStoreInfo keyStoreInfo = getKeyStoreInfoFromSign(); Assert.assertNotNull(keyStoreInfo); System.out.println("keyStoreInfo: "); System.out.println(keyStoreInfo.getAddress()); System.out.println(keyStoreInfo.getPublicKey()); System.out.println(keyStoreInfo.getPrivateKey()); // local guomi Credentials credentials = GenCredential.create(keyStoreInfo.getPrivateKey()); String pub = Numeric.toHexStringWithPrefix(credentials.getEcKeyPair().getPublicKey()); String addr = credentials.getAddress(); System.out.println("local transfer: "); System.out.println(pub); System.out.println(addr); Assert.assertTrue(keyStoreInfo.getPublicKey().equals(pub)); Assert.assertTrue(keyStoreInfo.getAddress().equals(addr)); }
Example 2
Source File: FiscoBcosBroker4ProducerTest.java From WeEvent with Apache License 2.0 | 6 votes |
/** * publish an externally signed event by external account. */ @Test public void testPublishByExternalAccount() throws Exception { Credentials externallyCredentials = getExternalAccountCredentials(); String operatorAddress = externallyCredentials.getAddress(); // add operatorAddress for topic boolean result = this.iProducer.addOperator(this.groupId, this.topicName, operatorAddress); Assert.assertTrue(result); // publish event with the above generated externally account Map<String, String> ext = new HashMap<>(); ext.put(WeEvent.WeEvent_SIGN, "true"); WeEvent event = new WeEvent(this.topicName, "this is a signed message".getBytes(), ext); String rawData = buildWeEvent(event); ExtendedRawTransaction rawTransaction = getRawTransaction(this.groupId, rawData, this.contractContext); String signData = signData(rawTransaction, externallyCredentials); SendResult sendResult = this.iProducer.publish(new WeEvent(this.topicName, signData.getBytes(), ext), this.groupId).get(transactionTimeout, TimeUnit.MILLISECONDS); Assert.assertEquals(sendResult.getStatus(), SendResult.SendResultStatus.SUCCESS); }
Example 3
Source File: AccountUtils.java From web3sdk with Apache License 2.0 | 6 votes |
public static Account newAccount(boolean flag) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { // guomi Account account = new Account(); if (flag) { EncryptType.encryptType = 1; account.setEncryptType("guomi"); } else { EncryptType.encryptType = 0; account.setEncryptType("standard"); } Credentials credentials = GenCredential.create(); String address = credentials.getAddress(); String privateKey = credentials.getEcKeyPair().getPrivateKey().toString(16); String publicKey = credentials.getEcKeyPair().getPublicKey().toString(16); account.setAddress(address); account.setPrivateKey(privateKey); account.setPublicKey(publicKey); return account; }
Example 4
Source File: KeyStoreServiceTest.java From WeBASE-Front with Apache License 2.0 | 5 votes |
@Test public void loadPrivateKeyTest() throws Exception { String privateKey = "71f1479d9051e8d6b141a3b3ef9c01a7756da823a0af280c6bf62d18ee0cc978"; Credentials credentials = GenCredential.create(privateKey); // private key 实例 BigInteger privateKeyInstance = credentials.getEcKeyPair().getPrivateKey(); System.out.println(Numeric.toHexStringNoPrefix(privateKeyInstance)); // public key 实例 BigInteger publicKeyInstance = credentials.getEcKeyPair().getPublicKey(); System.out.println(Numeric.toHexString(publicKeyInstance.toByteArray())); String address = credentials.getAddress(); System.out.println(address); }
Example 5
Source File: KeyStoreService.java From WeBASE-Transaction with Apache License 2.0 | 5 votes |
/** * get user Address. * * @return */ public String getAddress() throws BaseException { try { String privateKey = properties.getPrivateKey(); Credentials credentials = GenCredential.create(privateKey); return credentials.getAddress(); } catch (Exception e) { log.error("getAddress fail."); throw new BaseException(ConstantCode.SYSTEM_ERROR); } }
Example 6
Source File: KeyStoreService.java From WeBASE-Transaction with Apache License 2.0 | 5 votes |
/** * get random Address. * * @return */ public String getRandomAddress() throws BaseException { try { Credentials credentials = GenCredential.create(); return credentials.getAddress(); } catch (Exception e) { log.error("getRandomAddress fail."); throw new BaseException(ConstantCode.SYSTEM_ERROR); } }
Example 7
Source File: BcosApp.java From evidenceSample with Apache License 2.0 | 4 votes |
public String getPublicKey(String keyStoreFileName,String keyStorePassword, String keyPassword) throws Exception{ Credentials credentials=loadkey(keyStoreFileName, keyStorePassword, keyPassword); return credentials.getAddress(); }