Java Code Examples for org.fisco.bcos.web3j.crypto.Keys#createEcKeyPair()
The following examples show how to use
org.fisco.bcos.web3j.crypto.Keys#createEcKeyPair() .
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: ImportCertTest.java From WeBASE-Node-Manager with Apache License 2.0 | 6 votes |
/** * address到底需不需要传入pub的开头的两位04 * 答案: 不需要,公钥是128位的 */ @Test public void testAddress() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { ECKeyPair key = Keys.createEcKeyPair(); // 用byte[]穿进去获取公钥,就会可能多出一位0 byte[] pubBytes = key.getPublicKey().toByteArray(); System.out.println("=============原生的=============="); System.out.println(key.getPublicKey()); //64bytes BigInteger System.out.println(Keys.getAddress(key.getPublicKey())); System.out.println("===========通过转成hex后获取地址============"); System.out.println(Numeric.toHexStringNoPrefix(key.getPublicKey())); //Hex后显示 System.out.println(Keys.getAddress(Numeric.toHexStringNoPrefix(key.getPublicKey()))); System.out.println("===========通过byte[]============"); System.out.println(Numeric.toHexStringNoPrefix(pubBytes)); // BigInteget=> byte[] => hex 多一位 System.out.println(Keys.getAddress(Numeric.toHexStringNoPrefix(pubBytes))); System.out.println("==============="); // System.out.println(Keys.getAddress(pubBytes)); }
Example 2
Source File: KeyStoreService.java From WeBASE-Transaction with Apache License 2.0 | 6 votes |
/** * get KeyStoreInfo. * * @return */ public KeyStoreInfo getKey() throws BaseException { try { ECKeyPair keyPair = Keys.createEcKeyPair(); String publicKey = Numeric.toHexStringWithPrefixZeroPadded(keyPair.getPublicKey(), PUBLIC_KEY_LENGTH_IN_HEX); String privateKey = Numeric.toHexStringNoPrefix(keyPair.getPrivateKey()); String address = "0x" + Keys.getAddress(publicKey); KeyStoreInfo keyStoreInfo = new KeyStoreInfo(); keyStoreInfo.setPublicKey(publicKey); keyStoreInfo.setPrivateKey(privateKey); keyStoreInfo.setAddress(address); return keyStoreInfo; } catch (Exception e) { log.error("createEcKeyPair fail."); throw new BaseException(ConstantCode.SYSTEM_ERROR); } }
Example 3
Source File: KeyPairUtils.java From WeBASE-Sign with Apache License 2.0 | 5 votes |
/** * init ecdsa key pair * @return ECKeyPair ecdsa */ private ECKeyPair createECDSAKeyPair() { try { ECKeyPair keyPair = Keys.createEcKeyPair(); return keyPair; } catch (Exception e) { log.error("KeyPairUtils create keypair of ECDSA failed, error msg:" + e.getMessage()); return null; } }
Example 4
Source File: GenCredential.java From web3sdk with Apache License 2.0 | 5 votes |
private static ECKeyPair createECDSAKeyPair() { try { ECKeyPair keyPair = Keys.createEcKeyPair(); return keyPair; } catch (Exception e) { logger.error("create keypair of ECDSA failed, error msg:" + e.getMessage()); return null; } }
Example 5
Source File: TableTestClient.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // init the Service ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(args[0])); service.run(); // run the daemon service // init the client keys keyPair = Keys.createEcKeyPair(); credentials = GenCredential.create(keyPair.getPrivateKey().toString(16)); logger.info("-----> start test !"); logger.info("init AOMP ChannelEthereumService"); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); channelEthereumService.setTimeout(5 * 1000); try { web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0])); } catch (Exception e) { System.out.println("\nPlease provide groupID in the first paramters"); System.exit(0); } if (args.length > 1) { if ("deploy".equals(args[1])) { deployTableTest(); } else { String[] params = new String[args.length - 1]; for (int i = 0; i < params.length; i++) params[i] = args[i + 1]; testTableTest(params); } } else { System.out.println( "\nPlease choose follow commands:\n deploy, create, insert, select, update or remove"); } System.exit(0); }
Example 6
Source File: OkClient.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // init the Service ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(args[0])); service.run(); // run the daemon service // init the client keys keyPair = Keys.createEcKeyPair(); credentials = Credentials.create(keyPair); logger.info("-----> start test !"); logger.info("init AOMP ChannelEthereumService"); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); try { web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0])); } catch (Exception e) { System.out.println("\nPlease provide groupID in the first paramters"); System.exit(0); } if (args.length > 1) { if ("deploy".equals(args[1])) { deployOk(); } else { String[] params = new String[args.length - 1]; for (int i = 0; i < params.length; i++) params[i] = args[i + 1]; testOk(params); } } else { System.out.println("\nPlease choose follow commands:\n deploy, trans or get"); } System.exit(0); }
Example 7
Source File: MixContractClient.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // init the Service ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(args[0])); service.run(); // run the daemon service // init the client keys keyPair = Keys.createEcKeyPair(); credentials = Credentials.create(keyPair); logger.info("-----> start test !"); logger.info("init AOMP ChannelEthereumService"); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); try { web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0])); } catch (Exception e) { System.out.println("\nPlease provide groupID in the first paramters"); System.exit(0); } if (args.length > 1) { if ("deploy".equals(args[1])) { deploymixContract(); } else { String[] params = new String[args.length - 1]; for (int i = 0; i < params.length; i++) params[i] = args[i + 1]; testMixContract(params); } } else { System.out.println( "\nPlease choose follow commands:\n deploy, create, insert, select, update or remove"); } System.exit(0); }
Example 8
Source File: GMTableTestClient.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { // init the Service ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(args[0])); service.run(); // run the daemon service // init the client keys keyPair = Keys.createEcKeyPair(); credentials = GenCredential.create(keyPair.getPrivateKey().toString(16)); logger.info("-----> start test !"); logger.info("init AOMP ChannelEthereumService"); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); channelEthereumService.setTimeout(5 * 1000); try { web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0])); } catch (Exception e) { System.out.println("\nPlease provide groupID in the first parameters"); System.exit(0); } if (args.length > 1) { if ("deploy".equals(args[1])) { deployTableTest(); } else { String[] params = new String[args.length - 1]; for (int i = 0; i < params.length; i++) params[i] = args[i + 1]; testTableTest(params); } } else { System.out.println( "\nPlease choose follow commands:\n deploy, create, insert, select, update or remove"); } System.exit(0); }
Example 9
Source File: TestTxDecode.java From web3sdk with Apache License 2.0 | 5 votes |
public static TransactionReceipt sentTx() throws Exception { // init the Service ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.run(); ECKeyPair keyPair = Keys.createEcKeyPair(); Credentials credentials = Credentials.create(keyPair); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); service.setGroupId(1); Web3j web3j = Web3j.build(channelEthereumService, service.getGroupId()); RemoteCall<TableTest> deploy = TableTest.deploy( web3j, credentials, new StaticGasProvider( new BigInteger("30000000"), new BigInteger("30000000"))); TableTest tableTest = deploy.send(); tableTest.create().send(); String name = "fruit"; int item_id = 1; String item_name = "apple"; RemoteCall<TransactionReceipt> insert = tableTest.insert(name, BigInteger.valueOf(item_id), item_name); TransactionReceipt txReceipt = insert.send(); return txReceipt; }