Java Code Examples for org.fisco.bcos.web3j.utils.Numeric#toHexStringWithPrefixZeroPadded()

The following examples show how to use org.fisco.bcos.web3j.utils.Numeric#toHexStringWithPrefixZeroPadded() . 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: KeyStoreService.java    From WeBASE-Transaction with Apache License 2.0 6 votes vote down vote up
/**
 * 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 2
Source File: KeyStoreService.java    From WeBASE-Front with Apache License 2.0 5 votes vote down vote up
/**
 * convert ECKeyPair to KeyStoreInfo.
 * default aes true
 */
private KeyStoreInfo keyPair2KeyStoreInfo(ECKeyPair keyPair, String userName) {
    String publicKey = Numeric
            .toHexStringWithPrefixZeroPadded(keyPair.getPublicKey(), PUBLIC_KEY_LENGTH_IN_HEX);
    String privateKey = Numeric.toHexStringNoPrefix(keyPair.getPrivateKey());
    String address = "0x" + Keys.getAddress(keyPair.getPublicKey());
    log.debug("publicKey:{} privateKey:{} address:{}", publicKey, privateKey, address);
    KeyStoreInfo keyStoreInfo = new KeyStoreInfo();
    keyStoreInfo.setPublicKey(publicKey);
    keyStoreInfo.setAddress(address);
    keyStoreInfo.setPrivateKey(privateKey);
    keyStoreInfo.setUserName(userName);
    return keyStoreInfo;
}
 
Example 3
Source File: KeyStoreService.java    From WeBASE-Sign with Apache License 2.0 5 votes vote down vote up
/**
 * keyPair to keyStoreInfo.
 * 1.3.0 use AddressUtil to get address instead of using Keys.java
 * @param encryptType 1: guomi, 0: standard
 */
private KeyStoreInfo keyPair2KeyStoreInfo(ECKeyPair keyPair, int encryptType) {
    String publicKey = Numeric
            .toHexStringWithPrefixZeroPadded(keyPair.getPublicKey(), PUBLIC_KEY_LENGTH_IN_HEX);
    String privateKey = Numeric.toHexStringNoPrefix(keyPair.getPrivateKey());
    String address = "0x" + addressUtils.getAddressByType(keyPair.getPublicKey(), encryptType);
    log.debug("publicKey:{} privateKey:{} address:{}", publicKey, privateKey, address);
    KeyStoreInfo keyStoreInfo = new KeyStoreInfo();
    keyStoreInfo.setPublicKey(publicKey);
    keyStoreInfo.setPrivateKey(aesUtils.aesEncrypt(privateKey));
    keyStoreInfo.setAddress(address);
    return keyStoreInfo;
}
 
Example 4
Source File: TopicTools.java    From web3sdk with Apache License 2.0 5 votes vote down vote up
public static String boolToTopic(boolean b) {
    if (b) {
        return Numeric.toHexStringWithPrefixZeroPadded(BigInteger.ONE, 64);
    } else {
        return Numeric.toHexStringWithPrefixZeroPadded(BigInteger.ZERO, 64);
    }
}
 
Example 5
Source File: TopicTools.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
public static String integerToTopic(BigInteger i) {
    return Numeric.toHexStringWithPrefixZeroPadded(i, 64);
}
 
Example 6
Source File: Address.java    From web3sdk with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return Numeric.toHexStringWithPrefixZeroPadded(value.getValue(), LENGTH_IN_HEX);
}
 
Example 7
Source File: AddressUtils.java    From WeBASE-Sign with Apache License 2.0 2 votes vote down vote up
/**
 * @param publicKey BigInteger
 * @param encryptType 1: guomi, 0: standard
 * @return
 */
public String getAddressByType(BigInteger publicKey, int encryptType) {
	String publicKeyHex = Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX);
	return getAddressByType(publicKeyHex, encryptType);
}