io.nuls.core.tools.crypto.Hex类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中io.nuls.core.tools.crypto.Hex类的一些代码示例,展示了Hex类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hex类的具体详情如下:
包路径:io.nuls.core.tools.crypto.Hex
类名称:Hex

Hex介绍

[英]16进制编码解码类
[中]16进制编码解码类

代码示例

代码示例来源:origin: nuls-io/nuls

@Override
public String toString() {
  return Hex.encode(bytes);
}

代码示例来源: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

byte[] priKeyBytes = AESEncrypt.decrypt(Hex.decode(priKey), password);
Account tempAccount = AccountTool.createAccount(Hex.encode(priKeyBytes));
if (!address.equals(tempAccount.getAddress().getBase58())) {
  return Result.getFailed(AccountErrorCode.PARAMETER_ERROR).toRpcClientResult();
Result result = getEncryptedPrivateKey(address, Hex.encode(priKeyBytes), newPassword);
if (result.isSuccess()) {
  Map<String, Boolean> map = new HashMap<>();

代码示例来源:origin: nuls-io/nuls

ECKey key = ECKey.fromPrivate(new BigInteger(1, Hex.decode(priKey)));
try {
  String newAddress = AccountTool.newAddress(key).getBase58();
  account.encrypt(password);
  Map<String, String> map = new HashMap<>();
  map.put("value", Hex.encode(account.getEncryptedPriKey()));
  return Result.getSuccess().setData(map).toRpcClientResult();
} catch (NulsException e) {

代码示例来源:origin: nuls-io/nuls

/**
 * 获取私匙转16进制后的字符串
 *
 * @return String
 */
@JsonIgnore
public String getPrivateKeyAsHex() {
  return Hex.encode(getPrivKeyBytes());
}

代码示例来源: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

privateKeyBytes = AESEncrypt.decrypt(Hex.decode(priKey), form.getPassword());
    } catch (CryptoException e) {
      return Result.getFailed(AccountLedgerErrorCode.PARAMETER_ERROR).toRpcClientResult();
    priKey = Hex.encode(privateKeyBytes);
  } else {
    return Result.getFailed(AccountLedgerErrorCode.PARAMETER_ERROR).toRpcClientResult();
ECKey key = ECKey.fromPrivate(new BigInteger(1, Hex.decode(priKey)));
try {
  String newAddress = AccountTool.newAddress(key).getBase58();
  byte[] data = Hex.decode(form.getTxHex());
  Transaction tx = TransactionManager.getInstance(new NulsByteBuffer(data));
  tx = accountLedgerService.signTransaction(tx, key);
  map.put("value", Hex.encode(tx.serialize()));
  return Result.getSuccess().setData(map).toRpcClientResult();
} catch (Exception e) {

代码示例来源:origin: nuls-io/nuls

public static String getTxHash(byte[] fromBytes) {
  byte[] txBytes = getTxHashBytes(fromBytes);
  if(txBytes != null) {
    return Hex.encode(txBytes);
  }
  return null;
}

代码示例来源:origin: nuls-io/nuls

@Deprecated
public Sha256Hash(String hexString) {
  Util.checkState(hexString.length() == LENGTH * 2);
  this.bytes = Hex.decode(hexString);
}

代码示例来源:origin: nuls-io/nuls

byte[] priKey = null;
if (null != keyStore.getPrikey() && keyStore.getPrikey().length > 0) {
  if (!ECKey.isValidPrivteHex(Hex.encode(keyStore.getPrikey()))) {
    return Result.getFailed(AccountErrorCode.PARAMETER_ERROR);
    account = AccountTool.createAccount(Hex.encode(priKey));
  } catch (NulsException e) {
    return Result.getFailed(e.getErrorCode());
    priKey = AESEncrypt.decrypt(Hex.decode(keyStore.getEncryptedPrivateKey()), password);
    account = AccountTool.createAccount(Hex.encode(priKey));
  } catch (CryptoException e) {
    return Result.getFailed(AccountErrorCode.PASSWORD_IS_WRONG);

代码示例来源:origin: nuls-io/nuls

public static String getTxHash(byte[] fromBytes) {
  byte[] txBytes = getTxHashBytes(fromBytes);
  if(txBytes != null) {
    return Hex.encode(txBytes);
  }
  return null;
}

代码示例来源: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

public String getPublicKeyAsHex(boolean compressed) {
  return Hex.encode(getPubKey(compressed));
}

代码示例来源: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

@Override
  public String toString() {
    return "ContractResult{" +
        "contractAddress=" + AddressTool.getStringAddressByBytes(contractAddress) +
        ", result='" + result + '\'' +
        ", gasUsed=" + gasUsed +
        ", stateRoot=" + (stateRoot != null ? Hex.encode(stateRoot) : stateRoot ) +
        ", value=" + value +
        ", revert=" + revert +
        ", error=" + error +
        ", errorMessage='" + errorMessage + '\'' +
        ", stackTrace='" + stackTrace + '\'' +
        ", balance=" + (balance != null ? balance.toString() : null) +
        ", nonce=" + nonce +
        ", transfersSize=" + (transfers != null ? transfers.size() : 0) +
        ", eventsSize=" + (events != null ? events.size() : 0) +
        ", remark='" + remark + '\'' +
        '}';
  }
}

代码示例来源: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

@Override
  public String toString() {
    try {
      return Hex.encode(serialize());
    } catch (IOException e) {
      Log.error(e);
      return super.toString();
    }
  }
}

代码示例来源:origin: nuls-io/nuls

private byte[] getGenesisPubkey() {
    return ECKey.fromPrivate(new BigInteger(1, Hex.decode(priKey))).getPubKey();
  }
}

代码示例来源:origin: nuls-io/nuls

private int findSigInRedeem(byte[] signatureBytes, Sha256Hash hash) {
  checkArgument(chunks.get(0).isOpCode()); // P2SH scriptSig
  int numKeys = Script.decodeFromOpN(chunks.get(chunks.size() - 2).opcode);
  /* TransactionSignature signature = TransactionSignature.decodeFromBitcoin(signatureBytes, true);
  for (int i = 0 ; i < numKeys ; i++) {
    if (ECKey.fromPublicOnly(chunks.get(i + 1).data).verify(hash, signature)) {
      return i;
    }
  }*/
  throw new IllegalStateException("Could not find matching key for signature on " + hash.toString() + " sig " + Hex.encode(signatureBytes));
}

代码示例来源: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;
}

相关文章