本文整理了Java中io.nuls.core.tools.crypto.Hex.decode()
方法的一些代码示例,展示了Hex.decode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex.decode()
方法的具体详情如下:
包路径:io.nuls.core.tools.crypto.Hex
类名称:Hex
方法名:decode
[英]对16进制编码的字符串进行解码。
[中]对16进制编码的字符串进行解码。
代码示例来源:origin: nuls-io/nuls
@Override
public int compare(String k1, String k2) {
return comparator.compare(Hex.decode(k1), Hex.decode(k2));
}
};
代码示例来源:origin: nuls-io/nuls
public void addPubkeys(List<String> pubkeys) {
this.pubKeyList = new ArrayList<>();
for (String pubkeyStr : pubkeys) {
pubKeyList.add(Hex.decode(pubkeyStr));
}
}
代码示例来源:origin: nuls-io/nuls
public static String sha3(String src) {
if(src == null || src.length() == 0) {
return null;
}
try {
byte[] bytes = Hex.decode(src);
return sha3(bytes);
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: nuls-io/nuls
/**
* Creates a new instance that wraps the given hash value (represented as a hex string).
*
* @param hexString a hash value represented as a hex string
* @return a new instance
* @throws IllegalArgumentException if the given string is not a valid
* hex string, or if it does not represent exactly 32 bytes
*/
public static Sha256Hash wrap(String hexString) {
return wrap(Hex.decode(hexString));
}
代码示例来源:origin: nuls-io/nuls
@Deprecated
public Sha256Hash(String hexString) {
Util.checkState(hexString.length() == LENGTH * 2);
this.bytes = Hex.decode(hexString);
}
代码示例来源:origin: nuls-io/nuls
public static String keccak(String src) {
if(src == null || src.length() == 0) {
return null;
}
try {
byte[] bytes = Hex.decode(src);
return keccak(bytes);
} catch (Exception e) {
return null;
}
}
代码示例来源:origin: nuls-io/nuls
private byte[] getGenesisPubkey() {
return ECKey.fromPrivate(new BigInteger(1, Hex.decode(priKey))).getPubKey();
}
}
代码示例来源:origin: nuls-io/nuls
public static NulsDigestData fromDigestHex(String hex) throws NulsException {
byte[] bytes = Hex.decode(hex);
NulsDigestData hash = new NulsDigestData();
hash.parse(bytes, 0);
return hash;
}
代码示例来源:origin: nuls-io/nuls
private NulsSignData signature(byte[] bytes) throws NulsException {
AccountService service = NulsContext.getServiceBean(AccountService.class);
return service.signDigest(bytes, ECKey.fromPrivate(new BigInteger(1, Hex.decode(priKey))));
}
代码示例来源:origin: nuls-io/nuls
public AccountKeyStore toAccountKeyStore() {
AccountKeyStore accountKeyStore = new AccountKeyStore();
accountKeyStore.setAddress(this.address);
accountKeyStore.setAlias(this.alias);
accountKeyStore.setEncryptedPrivateKey(this.encryptedPrivateKey);
if (null == this.prikey || "null".toUpperCase().equals(this.prikey.trim().toUpperCase()) || "".equals(prikey.trim())) {
accountKeyStore.setPrikey(null);
} else {
try {
accountKeyStore.setPrikey(Hex.decode(this.prikey.trim()));
} catch (Exception e) {
accountKeyStore.setPrikey(null);
}
}
accountKeyStore.setPubKey(Hex.decode(this.pubKey));
return accountKeyStore;
}
代码示例来源:origin: nuls-io/nuls
/**
* Creates a program that requires at least N of the given keys to sign, using OP_CHECKMULTISIG.
* 根据多个公钥创建多重签名的OutputScript/scriptPublicKry
*/
public static Script createNulsMultiSigOutputScript(int threshold, List<String> pubkeys) {
checkArgument(threshold > 0);
checkArgument(threshold <= pubkeys.size());
checkArgument(pubkeys.size() <= 16); // That's the max we can represent with a single opcode.这是我们可以用一个操作码来表示的最大值
ScriptBuilder builder = new ScriptBuilder();
builder.smallNum(threshold);
for (String pubKey : pubkeys) {
builder.data(Hex.decode(pubKey));
}
builder.smallNum(pubkeys.size());
builder.op(OP_CHECKMULTISIG);
return builder.build();
}
代码示例来源:origin: nuls-io/nuls
@POST
@Path("/constructor")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "获取智能合约构造函数")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success", response = ContractInfoDto.class)
})
public RpcClientResult contractConstructor(@ApiParam(name = "createForm", value = "创建智能合约", required = true) ContractCode code) {
if (code == null) {
return Result.getFailed(ContractErrorCode.NULL_PARAMETER).toRpcClientResult();
}
String contractCode = code.getContractCode();
if(StringUtils.isBlank(contractCode)) {
return Result.getFailed(ContractErrorCode.NULL_PARAMETER).toRpcClientResult();
}
byte[] contractCodeBytes = Hex.decode(contractCode);
ContractInfoDto contractInfoDto = vmHelper.getConstructor(contractCodeBytes);
if(contractInfoDto == null || contractInfoDto.getConstructor() == null) {
return Result.getFailed(ContractErrorCode.ILLEGAL_CONTRACT).toRpcClientResult();
}
Map<String, Object> resultMap = MapUtil.createLinkedHashMap(2);
resultMap.put("constructor", contractInfoDto.getConstructor());
resultMap.put("isNrc20", contractInfoDto.isNrc20());
return Result.getSuccess().setData(resultMap).toRpcClientResult();
}
代码示例来源:origin: nuls-io/nuls
@POST
@Path("/transaction/broadcast")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "广播交易", notes = "result.data: resultJson 返回交易对象")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success")
})
public RpcClientResult broadcast(@ApiParam(name = "form", value = "交易信息", required = true) BroadHexTxForm form) {
if (StringUtils.isBlank(form.getTxHex())) {
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
try {
byte[] data = Hex.decode(form.getTxHex());
Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data));
Result result = accountLedgerService.broadcast(tx);
if (result.isSuccess()) {
Map<String, Object> map = new HashMap<>();
map.put("value", tx.getHash().getDigestHex());
result.setData(map);
}
return result.toRpcClientResult();
} catch (Exception e) {
Log.error(e);
return Result.getFailed(LedgerErrorCode.DATA_PARSE_ERROR).toRpcClientResult();
}
}
代码示例来源:origin: nuls-io/nuls
@POST
@Path("/validate/create")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "验证创建智能合约")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success")
})
public RpcClientResult validateCreateContract(@ApiParam(name = "validateCreateForm", value = "验证创建智能合约", required = true) ContractValidateCreate create) {
if (create == null || create.getGasLimit() < 0 || create.getPrice() < 0) {
return Result.getFailed(ContractErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
String contractCode = create.getContractCode();
if(StringUtils.isBlank(contractCode)) {
return Result.getFailed(ContractErrorCode.NULL_PARAMETER).toRpcClientResult();
}
byte[] contractCodeBytes = Hex.decode(contractCode);
ProgramMethod method = vmHelper.getMethodInfoByCode(ContractConstant.CONTRACT_CONSTRUCTOR, null, contractCodeBytes);
String[][] args = null;
if(method != null) {
args = create.getArgs(method.argsType2Array());
}
return contractTxService.validateContractCreateTx(
create.getGasLimit(),
create.getPrice(),
contractCodeBytes,
args).toRpcClientResult();
}
代码示例来源:origin: nuls-io/nuls
@Override
public Result getSignatureType(List<String> utxoList) {
//获取utxo中的tx_hash和index,根据tx_hash和index找到utxo,根据utxo的类型获取签名类型
byte signType = 0;
for (String utxo : utxoList) {
if ((signType & 0x01) == 0x01 && (signType & 0x02) == 0x02) {
break;
}
byte[] owner = Hex.decode(utxo);
Coin coin = ledgerService.getUtxo(owner);
if (coin == null) {
continue;
}
if (signType != 3) {
if ((signType & 0x01) == 0 && coin.getOwner().length == 23) {
signType = (byte) (signType | 0x01);
} else if ((signType & 0x02) == 0 && coin.getTempOwner().length != 23) {
signType = (byte) (signType | 0x02);
}
}
}
return Result.getSuccess().setData(signType);
}
}
代码示例来源:origin: nuls-io/nuls
@Override
public Result<Address> getAddress(String pubKey) {
AssertUtil.canNotEmpty(pubKey, "");
try {
Address address = AccountTool.newAddress(ECKey.fromPublicOnly(Hex.decode(pubKey)));
return Result.getSuccess().setData(address);
} catch (NulsException e) {
Log.error(e);
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
}
}
代码示例来源:origin: nuls-io/nuls
@POST
@Path("/transaction/validate")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "验证交易是否正确", notes = "result.data: resultJson 返回验证结果")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "success")
})
public RpcClientResult validate(@ApiParam(name = "form", value = "验证交易是否正确", required = true) BroadHexTxForm form) {
if (StringUtils.isBlank(form.getTxHex())) {
return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
try {
byte[] data = Hex.decode(form.getTxHex());
Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data));
ValidateResult validateResult = tx.verify();
if (validateResult.isFailed()) {
return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult();
}
validateResult = this.ledgerService.verifyCoinData(tx, new HashMap<>(), new HashSet<>());
if (validateResult.isFailed()) {
return Result.getFailed(validateResult.getErrorCode()).toRpcClientResult();
}
Result result = Result.getSuccess();
return result.toRpcClientResult();
} catch (Exception e) {
Log.error(e);
return Result.getFailed(LedgerErrorCode.DATA_PARSE_ERROR).toRpcClientResult();
}
}
代码示例来源:origin: nuls-io/nuls
public static byte[] getStateRoot(BlockHeader blockHeader) {
if (blockHeader == null || blockHeader.getExtend() == null) {
return null;
}
byte[] stateRoot = blockHeader.getStateRoot();
if (stateRoot != null && stateRoot.length > 0) {
return stateRoot;
}
try {
BlockExtendsData extendsData = new BlockExtendsData(blockHeader.getExtend());
stateRoot = extendsData.getStateRoot();
if ((stateRoot == null || stateRoot.length == 0) && NulsContext.MAIN_NET_VERSION > 1) {
stateRoot = Hex.decode(NulsContext.INITIAL_STATE_ROOT);
}
blockHeader.setStateRoot(stateRoot);
return stateRoot;
} catch (Exception e) {
Log.error("parse stateRoot of blockHeader error.", e);
return null;
}
}
代码示例来源:origin: nuls-io/nuls
public static Coin convertCoin(InputDto utxo) {
Coin coin = new Coin();
byte[] txHashBytes = Hex.decode(utxo.getFromHash());
coin.setOwner(ArraysTool.concatenate(txHashBytes, new VarInt(utxo.getFromIndex()).encode()));
coin.setLockTime(utxo.getLockTime());
coin.setNa(Na.valueOf(utxo.getValue()));
coin.setTempOwner(AddressTool.getAddress(utxo.getAddress()));
return coin;
}
代码示例来源:origin: nuls-io/nuls
public static Account createAccount(String prikey) throws NulsException {
ECKey key = null;
if (StringUtils.isBlank(prikey)) {
key = new ECKey();
} else {
try {
key = ECKey.fromPrivate(new BigInteger(1, Hex.decode(prikey)));
} catch (Exception e) {
throw new NulsException(AccountErrorCode.PRIVATE_KEY_WRONG, e);
}
}
Address address = new Address(NulsContext.getInstance().getDefaultChainId(), NulsContext.DEFAULT_ADDRESS_TYPE, SerializeUtils.sha256hash160(key.getPubKey()));
Account account = new Account();
account.setEncryptedPriKey(new byte[0]);
account.setAddress(address);
account.setPubKey(key.getPubKey());
account.setEcKey(key);
account.setPriKey(key.getPrivKeyBytes());
account.setCreateTime(TimeService.currentTimeMillis());
return account;
}
内容来源于网络,如有侵权,请联系作者删除!