Search in sources :

Example 11 with ECKeyPair

use of org.fisco.bcos.web3j.crypto.ECKeyPair in project web3sdk by FISCO-BCOS.

the class GenCredential method createGuomiKeyPair.

public static ECKeyPair createGuomiKeyPair(String privKey) {
    SM2KeyGenerator generator = new SM2KeyGenerator();
    final KeyPair keyPairData = generator.generateKeyPair(privKey);
    if (keyPairData != null)
        return genEcPairFromKeyPair(keyPairData);
    return null;
}
Also used : KeyPair(java.security.KeyPair) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) SM2KeyGenerator(org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator)

Example 12 with ECKeyPair

use of org.fisco.bcos.web3j.crypto.ECKeyPair in project web3sdk by FISCO-BCOS.

the class GenCredential method create.

public static Credentials create(ECKeyPair keyPair) {
    try {
        ECKeyPair newKeyPair = createKeyPair(keyPair.getPrivateKey().toString(16));
        if (newKeyPair == null)
            return null;
        Credentials credentials = Credentials.create(newKeyPair);
        return credentials;
    } catch (Exception e) {
        System.out.println("init credential from private key failed ");
        logger.error("init credential from private key failed, error msg:" + e.getMessage());
        return null;
    }
}
Also used : ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Example 13 with ECKeyPair

use of org.fisco.bcos.web3j.crypto.ECKeyPair in project web3sdk by FISCO-BCOS.

the class TestTxDecode method sentTx.

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;
}
Also used : StaticGasProvider(org.fisco.bcos.web3j.tx.gas.StaticGasProvider) ECKeyPair(org.fisco.bcos.web3j.crypto.ECKeyPair) TransactionReceipt(org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) Service(org.fisco.bcos.channel.client.Service) ChannelEthereumService(org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Web3j(org.fisco.bcos.web3j.protocol.Web3j) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BigInteger(java.math.BigInteger) Credentials(org.fisco.bcos.web3j.crypto.Credentials)

Aggregations

ECKeyPair (org.fisco.bcos.web3j.crypto.ECKeyPair)13 Credentials (org.fisco.bcos.web3j.crypto.Credentials)6 BigInteger (java.math.BigInteger)5 KeyPair (java.security.KeyPair)4 ApplicationContext (org.springframework.context.ApplicationContext)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 PrivateKey (java.security.PrivateKey)2 PublicKey (java.security.PublicKey)2 ECPrivateKey (java.security.interfaces.ECPrivateKey)2 Service (org.fisco.bcos.channel.client.Service)2 SM2KeyGenerator (org.fisco.bcos.web3j.crypto.gm.sm2.crypto.asymmetric.SM2KeyGenerator)2 Web3j (org.fisco.bcos.web3j.protocol.Web3j)2 ChannelEthereumService (org.fisco.bcos.web3j.protocol.channel.ChannelEthereumService)2 TransactionReceipt (org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt)2 RateLimiter (com.google.common.util.concurrent.RateLimiter)1 SecureRandom (java.security.SecureRandom)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ECPublicKey (org.bouncycastle.jce.interfaces.ECPublicKey)1 P12Manager (org.fisco.bcos.channel.client.P12Manager)1