org.fisco.bcos.web3j.crypto.gm.GenCredential Java Examples
The following examples show how to use
org.fisco.bcos.web3j.crypto.gm.GenCredential.
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: PublicKeyGmTest.java From WeBASE-Node-Manager with Apache License 2.0 | 6 votes |
@Test public void checkPubCorrect() throws IOException { String defaultUserPrivateKey = "SzK9KCjpyVCW0T9K9r/MSlmcpkeckYKVn/D1X7fzzp18MM7yHhUHQugTxKXVJJY5XWOb4zZ79IXMBu77zmXsr0mCRnATZTUqFfWLX6tUBIw="; String defaultPub = "0xc5d877bff9923af55f248fb48b8907dc7d00cac3ba19b4259aebefe325510af7bd0a75e9a8e8234aa7aa58bc70510ee4bef02201a86006196da4e771c47b71b4"; String defaultAddress = "0xf1585b8d0e08a0a00fff662e24d67ba95a438256"; Credentials credential = GenCredential.create(defaultUserPrivateKey); System.out.println("private: "); System.out.println(credential.getEcKeyPair().getPrivateKey()); System.out.println(Numeric.toHexStringNoPrefix(credential.getEcKeyPair().getPrivateKey())); System.out.println("pub: "); System.out.println(credential.getEcKeyPair().getPublicKey()); System.out.println("address: "); System.out.println(credential.getAddress()); System.out.println(Keys.getAddress(credential.getEcKeyPair().getPublicKey())); }
Example #2
Source File: TransactionEncoderTest.java From web3sdk with Apache License 2.0 | 6 votes |
@Ignore @Test public void testGMSignMessage() { EncryptType encryptType = new EncryptType(1); Credentials credentials = GenCredential.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6"); System.out.println(credentials.getEcKeyPair().getPublicKey().toString(16)); Credentials credentials1 = Credentials.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6"); System.out.println(credentials1.getEcKeyPair().getPublicKey().toString(16)); byte[] signedMessage = TransactionEncoder.signMessage(createContractTransaction(), credentials); String hexMessage = Numeric.toHexString(signedMessage); assertThat( hexMessage, is( "0xf8948201f4010a8201f5800a850000000000b8408234c544a9f3ce3b401a92cc7175602ce2a1e29b1ec135381c7d2a9e8f78f3edc9c06ee55252857c9a4560cb39e9d70d40f4331cace4d2b3121b967fa7a829f0a03d8627050f6688f27e2b5b89c9c141d3a48603029849e088486d1c7ea079ea7fa037024ed35d2c099d7eb68fb133e57735b03605ec32ded39ab305c3b56e5d99e7")); }
Example #3
Source File: PerformanceDTTest.java From web3sdk with Apache License 2.0 | 6 votes |
public void initialize(String groupId) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(groupId)); service.run(); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); Web3AsyncThreadPoolSize.web3AsyncCorePoolSize = 3000; Web3AsyncThreadPoolSize.web3AsyncPoolSize = 2000; ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500); web3 = Web3j.build( channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId)); credentials = GenCredential.create(); transactionManager = Contract.getTheTransactionManager(web3, credentials); }
Example #4
Source File: TestBase.java From web3sdk with Apache License 2.0 | 6 votes |
@BeforeClass public static void setUpBeforeClass() throws Exception { context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.run(); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); System.out.println("EncryptType => " + EncryptType.getEncryptType()); web3j = Web3j.build(channelEthereumService, service.getGroupId()); credentials = GenCredential.create(); Ok ok = Ok.deploy(web3j, credentials, new StaticGasProvider(gasPrice, gasLimit)).send(); blockNumber = ok.getTransactionReceipt().get().getBlockNumber(); blockHash = ok.getTransactionReceipt().get().getBlockHash(); txHash = ok.getTransactionReceipt().get().getTransactionHash(); }
Example #5
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 #6
Source File: SigServiceApp.java From group-signature-client with GNU General Public License v3.0 | 6 votes |
public boolean loadConfig() throws Exception { System.out.println("please wait ..."); Service service; try { context = new ClassPathXmlApplicationContext("classpath:node/application.xml"); service = context.getBean(Service.class); service.run(); } catch (Exception e) { logger.error("load config failed, error msg: " + e.getMessage()); throw new Exception("load config failed, error msg: " + e.getMessage()); } credentials = GenCredential.create(); // channel eth service ChannelEthereumService channelService = new ChannelEthereumService(); channelService.setChannelService(service); channelService.setTimeout(5000); web3j = Web3j.build(channelService, service.getGroupId()); return true; }
Example #7
Source File: TransactionEncoderTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testGMCrendetial() { for (int i = 0; i < 10; i++) { Instant systartTime = Instant.now(); GenCredential.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f"+i); System.out.println(" siyao useTime: " + Duration.between(systartTime, Instant.now()).toMillis()); // gm createTransaction! EncryptType encryptType = new EncryptType(1); assertSame(encryptType.getEncryptType(),1); Instant gmsystartTime = Instant.now(); GenCredential.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f"+i); // System.out.println(gmcredentials.getEcKeyPair().getPublicKey().toString(16)); System.out.println(encryptType+ " gmsiyao useTime: " + Duration.between(gmsystartTime, Instant.now()).toMillis()); } }
Example #8
Source File: PublicKeyTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void checkPubCorrect() throws IOException { String defaultUserPrivateKeyAfterAes = "SzK9KCjpyVCW0T9K9r/MSlmcpkeckYKVn/D1X7fzzp18MM7yHhUHQugTxKXVJJY5XWOb4zZ79IXMBu77zmXsr0mCRnATZTUqFfWLX6tUBIw="; String defaultPub = "0xc5d877bff9923af55f248fb48b8907dc7d00cac3ba19b4259aebefe325510af7bd0a75e9a8e8234aa7aa58bc70510ee4bef02201a86006196da4e771c47b71b4"; String defaultAddress = "0xf1585b8d0e08a0a00fff662e24d67ba95a438256"; String defaultUserPrivateKey = aesUtils.aesDecrypt(defaultUserPrivateKeyAfterAes); System.out.println("decrypt aes"); System.out.println(defaultUserPrivateKey); Credentials credential = GenCredential.create(defaultUserPrivateKey); System.out.println("private: "); System.out.println(credential.getEcKeyPair().getPrivateKey()); System.out.println(Numeric.toHexStringNoPrefix(credential.getEcKeyPair().getPrivateKey())); System.out.println("pub: "); System.out.println(credential.getEcKeyPair().getPublicKey()); System.out.println("address: "); System.out.println(credential.getAddress()); System.out.println(Keys.getAddress(credential.getEcKeyPair().getPublicKey())); }
Example #9
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 #10
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testConfigManager() throws Exception { address = "0x832f299af98c215f7ada010a966b12126483cd00"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); PermissionService permissionService = new PermissionService(web3j, credentialsPEM); // TablePermission System.out.println(permissionService.grantSysConfigManager(address)); assertNotNull(permissionService.grantSysConfigManager(address)); System.out.println(permissionService.listSysConfigManager().get(0).getAddress()); assertTrue(permissionService.listSysConfigManager().size() != 0); System.out.println(permissionService.revokeSysConfigManager(address)); assertNotNull(permissionService.revokeSysConfigManager(address)); }
Example #11
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testCNSManager() throws Exception { address = "0x832f299af98c215f7ada010a966b12126483cd00"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); PermissionService permissionService = new PermissionService(web3j, credentialsPEM); // TablePermission System.out.println(permissionService.grantCNSManager(address)); assertNotNull(permissionService.grantCNSManager(address)); System.out.println(permissionService.listCNSManager().get(0).getAddress()); assertTrue(permissionService.listCNSManager().size() != 0); System.out.println(permissionService.revokeCNSManager(address)); assertNotNull(permissionService.revokeCNSManager(address)); }
Example #12
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testNodeManger() throws Exception { address = "0x832f299af98c215f7ada010a966b12126483cd00"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); PermissionService permissionService = new PermissionService(web3j, credentialsPEM); // TablePermission System.out.println(permissionService.grantNodeManager(address)); assertNotNull(permissionService.grantNodeManager(address)); System.out.println(permissionService.listNodeManager().get(0).getAddress()); assertTrue(permissionService.listNodeManager().size() != 0); System.out.println(permissionService.revokeNodeManager(address)); assertNotNull(permissionService.revokeNodeManager(address)); }
Example #13
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testDeployAndCreateManager() throws Exception{ // 普通账户 address = "0x832f299af98c215f7ada010a966b12126483cd00"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); // 链管理员账户签名的PermissionService PermissionService permissionService = new PermissionService(web3j, credentialsPEM); // TablePermission System.out.println(permissionService.grantDeployAndCreateManager(address)); System.out.println(permissionService.grantDeployAndCreateManager(address)); assertNotNull(permissionService.grantDeployAndCreateManager(address)); System.out.println(permissionService.listDeployAndCreateManager().get(0).getAddress()); assertTrue(permissionService.listDeployAndCreateManager().size() != 0); // System.out.println(permissionService.revokeDeployAndCreateManager(address)); // assertNotNull(permissionService.revokeDeployAndCreateManager(address)); }
Example #14
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testPermissionManager() throws Exception{ address = "0x832f299af98c215f7ada010a966b12126483cd00"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); PermissionService permissionService = new PermissionService(web3j, credentialsPEM); System.out.println(permissionService.grantPermissionManager(address)); assertNotNull(permissionService.grantPermissionManager(address)); System.out.println(permissionService.listPermissionManager().get(0).getAddress()); assertTrue(permissionService.listPermissionManager().size() != 0); System.out.println(permissionService.revokePermissionManager(address)); assertNotNull(permissionService.revokePermissionManager(address)); }
Example #15
Source File: PrecompiledSysConfigServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testSystemConfig() throws Exception { key = "tx_count_limit"; // key: tx_count_limit, tx_gas_limit value = "300000001"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //链管理员私钥加载 Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); SystemConfigService systemConfigService = new SystemConfigService(web3j, credentialsPEM); System.out.println(web3j.getSystemConfigByKey(key).send().getResult()); System.out.println(systemConfigService.setValueByKey(key, value)); assertNotNull(systemConfigService.setValueByKey(key, value)); System.out.println(web3j.getSystemConfigByKey(key).send().getResult()); assertNotNull(web3j.getSystemConfigByKey(key)); }
Example #16
Source File: PermissionServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testUserTableManager() throws Exception{ String tableName = "t_test"; address = "0xd5bba8fe456fce310f529edecef902e4b63129b1"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //生成web3sdk使用的Credentials Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); PermissionService permissionService = new PermissionService(web3j, credentialsPEM); // TablePermission System.out.println(permissionService.grantUserTableManager(tableName, address)); assertNotNull(permissionService.grantUserTableManager(tableName, address)); // List<PermissionInfo> list = permissionService.listUserTableManager(tableName); // assertTrue(permissionService.listUserTableManager(tableName).size() != 0); // System.out.println(permissionService.revokeUserTableManager(tableName, address)); // assertNotNull(permissionService.revokeUserTableManager(tableName, address)); }
Example #17
Source File: ConsensusServiceTest.java From WeBASE-Front with Apache License 2.0 | 6 votes |
@Test public void testConsensus() throws Exception { nodeId = "224e6ee23e8a02d371298b9aec828f77cc2711da3a981684896715a3711885a3177b3cf7906bf9d1b84e597fad1e0049511139332c04edfe3daddba5ed60cffa"; context = new ClassPathXmlApplicationContext("applicationContext.xml"); PEMManager pem = context.getBean(PEMManager.class); ECKeyPair pemKeyPair = pem.getECKeyPair(); //链管理员私钥加载 Credentials credentialsPEM = GenCredential.create(pemKeyPair.getPrivateKey().toString(16)); ConsensusService consensusService = new ConsensusService(web3j, credentialsPEM); System.out.println(consensusService.addSealer(nodeId)); assertNotNull(consensusService.addSealer(nodeId)); System.out.println(consensusService.addObserver(nodeId)); assertNotNull(consensusService.addObserver(nodeId)); System.out.println(consensusService.removeNode(nodeId)); assertNotNull(consensusService.removeNode(nodeId)); }
Example #18
Source File: KeyStoreService.java From WeBASE-Front with Apache License 2.0 | 6 votes |
/** * create key store locally and save * with private key */ public KeyStoreInfo createKeyStoreLocally(String userName) { log.info("start createKeyStore. userName:{}", userName); checkUserNameAndTypeNotExist(userName, KeyTypes.LOCALUSER.getValue()); // create keyPair(support guomi) KeyStoreInfo keyStoreInfo; try { ECKeyPair keyPair = GenCredential.createKeyPair(); keyStoreInfo = keyPair2KeyStoreInfo(keyPair, userName); } catch (Exception e) { log.error("fail createKeyStore.", e); throw new FrontException("create keyInfo failed"); } keyStoreInfo.setType(KeyTypes.LOCALUSER.getValue()); String realPrivateKey = keyStoreInfo.getPrivateKey(); keyStoreInfo.setPrivateKey(aesUtils.aesEncrypt(realPrivateKey)); return keystoreRepository.save(keyStoreInfo); }
Example #19
Source File: Web3SDKConnector.java From WeEvent with Apache License 2.0 | 5 votes |
public static Credentials getCredentials(FiscoConfig fiscoConfig) { log.debug("begin init Credentials"); // read OSSCA account String privateKey; if (fiscoConfig.getWeb3sdkEncryptType().equals("SM2_TYPE")) { log.info("SM2_TYPE"); try { PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); Resource resource = resolver.getResource("classpath:" + fiscoConfig.getPemKeyPath()); PEMManager pemManager = new PEMManager(); pemManager.load(resource.getInputStream()); ECKeyPair pemKeyPair = pemManager.getECKeyPair(); privateKey = pemKeyPair.getPrivateKey().toString(16); } catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchProviderException | CertificateException | IOException e) { log.error("Init OSSCA Credentials failed", e); return null; } } else { privateKey = fiscoConfig.getAccount(); } Credentials credentials = GenCredential.create(privateKey); if (null == credentials) { log.error("init Credentials failed"); return null; } log.info("init Credentials success"); return credentials; }
Example #20
Source File: UserControllerTest.java From WeBASE-Node-Manager with Apache License 2.0 | 5 votes |
@Test public void testGenerateKey() throws Exception { // guomi use GenCredential Credentials credentials = GenCredential.create("3bed914595c159cbce70ec5fb6aff3d6797e0c5ee5a7a9224a21cae8932d84a4"); System.out.println( credentials.getAddress()); System.out.println( credentials.getEcKeyPair().getPrivateKey().toString(16)); System.out.println( credentials.getEcKeyPair().getPublicKey().toString(16)); }
Example #21
Source File: KeyStoreService.java From WeBASE-Front with Apache License 2.0 | 5 votes |
public KeyStoreInfo getKeyStoreInfoForQuery() { log.debug("start getKeyStoreInfoForQuery. "); // create keyPair(support guomi) KeyStoreInfo keyStoreInfo; try { ECKeyPair keyPair = GenCredential.createKeyPair(); return keyPair2KeyStoreInfo(keyPair, ""); } catch (Exception e) { log.error("fail getKeyStoreInfoForQuery.", e); throw new FrontException("create random keyInfo for query failed"); } }
Example #22
Source File: KeyStoreService.java From WeBASE-Front with Apache License 2.0 | 5 votes |
/** * get random credential to call transaction(not execute) * 2019/11/26 support guomi */ public Credentials getCredentialsForQuery() { log.debug("start getCredentialsForQuery. "); // create keyPair(support guomi) KeyStoreInfo keyStoreInfo; try { ECKeyPair keyPair = GenCredential.createKeyPair(); keyStoreInfo = keyPair2KeyStoreInfo(keyPair, ""); } catch (Exception e) { log.error("fail getCredentialsForQuery.", e); throw new FrontException("create random Credentials for query failed"); } return GenCredential.create(keyStoreInfo.getPrivateKey()); }
Example #23
Source File: CallContractTest.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { try { // 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 credentials = GenCredential.create(); logger.info("-----> start test in CallContractTest!"); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setTimeout(10 * 1000); channelEthereumService.setChannelService(service); web3j = Web3j.build(channelEthereumService, Integer.parseInt(args[0])); if (args.length == 2) { String address = args[1]; CallContract callContract = new CallContract(credentials, web3j); System.out.println( "************************ Test call & sendTrandation ************************"); testSyncCallContract(callContract, address); testAsyncCallContract(callContract, address); System.out.println("************************ Test decode ************************"); testDecode(callContract, address); System.out.println("Test CallContract successfully."); } else { System.out.println("Please input group id and contract address."); } } catch (Exception e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } System.exit(0); }
Example #24
Source File: PerformanceDTTest.java From web3sdk with Apache License 2.0 | 5 votes |
public void initialize(String groupId) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.setGroupId(Integer.parseInt(groupId)); service.run(); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); Web3AsyncThreadPoolSize.web3AsyncCorePoolSize = 3000; Web3AsyncThreadPoolSize.web3AsyncPoolSize = 2000; ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(500); Web3j web3 = Web3j.build( channelEthereumService, 15 * 100, scheduledExecutorService, Integer.parseInt(groupId)); Credentials credentials = GenCredential.create(); dagTransfer = DagTransfer.load( dagTransferAddr, web3, credentials, new StaticGasProvider( new BigInteger("30000000"), new BigInteger("30000000"))); transactionManager = Contract.getTheTransactionManager(web3, credentials); }
Example #25
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 #26
Source File: GMErc20Transaction.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { EncryptType encryptType = new EncryptType(1); System.out.println(encryptType.getEncryptType()); String groupId = "1"; ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.run(); System.out.println("==================================================================="); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); channelEthereumService.setTimeout(10000); Web3j web3 = Web3j.build(channelEthereumService, Integer.parseInt(groupId)); BigInteger gasPrice = new BigInteger("300000000"); BigInteger gasLimit = new BigInteger("300000000"); Credentials credentials1 = GenCredential.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6"); ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit); NewSolTest erc20 = NewSolTest.deploy(web3, credentials1, contractGasProvider).send(); for (int i = 0; i < 1; i++) { System.out.println("####contract address is: " + erc20.getContractAddress()); erc20.transfer("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e", new BigInteger("100")) .send(); BigInteger oldBalance = erc20.balanceOf("0x0f49a17d17f82da2a7d92ecf19268274150eaf5e").send(); System.out.println( "0x0f49a17d17f82da2a7d92ecf19268274150eaf5e balance" + oldBalance.intValue()); } System.exit(0); }
Example #27
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 #28
Source File: GMOkTransaction.java From web3sdk with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { EncryptType encryptType = new EncryptType(1); String groupId = "1"; ApplicationContext context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); Service service = context.getBean(Service.class); service.run(); System.out.println("==================================================================="); ChannelEthereumService channelEthereumService = new ChannelEthereumService(); channelEthereumService.setChannelService(service); channelEthereumService.setTimeout(10000); Web3j web3 = Web3j.build(channelEthereumService, Integer.parseInt(groupId)); BigInteger gasPrice = new BigInteger("300000000"); BigInteger gasLimit = new BigInteger("3000000000"); Credentials credentials1 = GenCredential.create( "a392604efc2fad9c0b3da43b5f698a2e3f270f170d859912be0d54742275c5f6"); ContractGasProvider contractGasProvider = new StaticGasProvider(gasPrice, gasLimit); final Ok okDemo = Ok.deploy(web3, credentials1, contractGasProvider).send(); for (int i = 0; i < 1; i++) { System.out.println("####contract address is: " + okDemo.getContractAddress()); TransactionReceipt receipt = okDemo.trans(new BigInteger("4")).send(); System.out.println(" balance = " + okDemo.get().send().intValue()); } System.exit(0); }
Example #29
Source File: ECKeyPairTest.java From web3sdk with Apache License 2.0 | 5 votes |
@Test public void encryptECKeyPairTestEmptyString() throws Exception { Credentials credentials = GenCredential.create(); ECKeyPair ecKeyPair = credentials.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")); }
Example #30
Source File: KeyStoreServiceTest.java From WeBASE-Front with Apache License 2.0 | 5 votes |
@Test public void testLoadP12() throws UnrecoverableKeyException, InvalidKeySpecException, NoSuchAlgorithmException, KeyStoreException, NoSuchProviderException, CertificateException, IOException { P12Manager p12Manager = new P12Manager(); p12Manager.setP12File("0x6399bda67f0ae8d1fdd997a885b8aee32a0c9696.p12"); p12Manager.setPassword("123"); p12Manager.load(); // c5658bbb9b905345e7c057690ec6f50c06dada711d1086820980496b4954fbc7 String privateKey = Numeric.toHexStringNoPrefix(p12Manager.getECKeyPair().getPrivateKey()); System.out.println("load private key: " + privateKey); String address = GenCredential.create(privateKey).getAddress(); System.out.println("address: " + address); Assert.assertTrue("pri error", address.equals("0x6399bda67f0ae8d1fdd997a885b8aee32a0c9696")); }