org.web3j.utils.Numeric.toHexStringNoPrefix()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(139)

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

Numeric.toHexStringNoPrefix介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

  1. static String encodeBool(Bool value) {
  2. byte[] rawValue = new byte[MAX_BYTE_LENGTH];
  3. if (value.getValue()) {
  4. rawValue[rawValue.length - 1] = 1;
  5. }
  6. return Numeric.toHexStringNoPrefix(rawValue);
  7. }

代码示例来源:origin: web3j/web3j

  1. public static String toHexStringWithPrefixSafe(BigInteger value) {
  2. String result = toHexStringNoPrefix(value);
  3. if (result.length() < 2) {
  4. result = Strings.zeros(1) + result;
  5. }
  6. return HEX_PREFIX + result;
  7. }

代码示例来源:origin: web3j/web3j

  1. static String encodeBytes(BytesType bytesType) {
  2. byte[] value = bytesType.getValue();
  3. int length = value.length;
  4. int mod = length % MAX_BYTE_LENGTH;
  5. byte[] dest;
  6. if (mod != 0) {
  7. int padding = MAX_BYTE_LENGTH - mod;
  8. dest = new byte[length + padding];
  9. System.arraycopy(value, 0, dest, 0, length);
  10. } else {
  11. dest = value;
  12. }
  13. return Numeric.toHexStringNoPrefix(dest);
  14. }

代码示例来源:origin: web3j/web3j

  1. private static String toHexStringZeroPadded(BigInteger value, int size, boolean withPrefix) {
  2. String result = toHexStringNoPrefix(value);
  3. int length = result.length();
  4. if (length > size) {
  5. throw new UnsupportedOperationException(
  6. "Value " + result + "is larger then length " + size);
  7. } else if (value.signum() < 0) {
  8. throw new UnsupportedOperationException("Value cannot be negative");
  9. }
  10. if (length < size) {
  11. result = Strings.zeros(size - length) + result;
  12. }
  13. if (withPrefix) {
  14. return HEX_PREFIX + result;
  15. } else {
  16. return result;
  17. }
  18. }

代码示例来源:origin: web3j/web3j

  1. static String encodeNumeric(NumericType numericType) {
  2. byte[] rawValue = toByteArray(numericType);
  3. byte paddingValue = getPaddingValue(numericType);
  4. byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH];
  5. if (paddingValue != 0) {
  6. for (int i = 0; i < paddedRawValue.length; i++) {
  7. paddedRawValue[i] = paddingValue;
  8. }
  9. }
  10. System.arraycopy(
  11. rawValue, 0,
  12. paddedRawValue, MAX_BYTE_LENGTH - rawValue.length,
  13. rawValue.length);
  14. return Numeric.toHexStringNoPrefix(paddedRawValue);
  15. }

代码示例来源:origin: web3j/web3j

  1. @Test
  2. public void testToHexStringNoPrefix() {
  3. assertThat(Numeric.toHexStringNoPrefix(BigInteger.TEN), is("a"));
  4. }

代码示例来源:origin: web3j/web3j

  1. Numeric.toHexStringNoPrefix(
  2. Numeric.toBytesPadded(
  3. new BigInteger(Long.toString(offset)), MAX_BYTE_LENGTH

代码示例来源:origin: web3j/web3j

  1. private static WalletFile createWalletFile(
  2. ECKeyPair ecKeyPair, byte[] cipherText, byte[] iv, byte[] salt, byte[] mac,
  3. int n, int p) {
  4. WalletFile walletFile = new WalletFile();
  5. walletFile.setAddress(Keys.getAddress(ecKeyPair));
  6. WalletFile.Crypto crypto = new WalletFile.Crypto();
  7. crypto.setCipher(CIPHER);
  8. crypto.setCiphertext(Numeric.toHexStringNoPrefix(cipherText));
  9. WalletFile.CipherParams cipherParams = new WalletFile.CipherParams();
  10. cipherParams.setIv(Numeric.toHexStringNoPrefix(iv));
  11. crypto.setCipherparams(cipherParams);
  12. crypto.setKdf(SCRYPT);
  13. WalletFile.ScryptKdfParams kdfParams = new WalletFile.ScryptKdfParams();
  14. kdfParams.setDklen(DKLEN);
  15. kdfParams.setN(n);
  16. kdfParams.setP(p);
  17. kdfParams.setR(R);
  18. kdfParams.setSalt(Numeric.toHexStringNoPrefix(salt));
  19. crypto.setKdfparams(kdfParams);
  20. crypto.setMac(Numeric.toHexStringNoPrefix(mac));
  21. walletFile.setCrypto(crypto);
  22. walletFile.setId(UUID.randomUUID().toString());
  23. walletFile.setVersion(CURRENT_VERSION);
  24. return walletFile;
  25. }

代码示例来源:origin: web3j/web3j

  1. @Test
  2. public void testGetAddressZeroPadded() {
  3. byte[] address = Keys.getAddress(
  4. Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE));
  5. String expected = Numeric.toHexStringNoPrefix(address);
  6. String value = "1234";
  7. assertThat(Keys.getAddress("0x"
  8. + Strings.zeros(Keys.PUBLIC_KEY_LENGTH_IN_HEX - value.length()) + value),
  9. equalTo(expected));
  10. }

代码示例来源:origin: web3j/web3j

  1. @Test
  2. public void testGetAddressSmallPublicKey() {
  3. byte[] address = Keys.getAddress(
  4. Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE));
  5. String expected = Numeric.toHexStringNoPrefix(address);
  6. assertThat(Keys.getAddress("0x1234"), equalTo(expected));
  7. }

代码示例来源:origin: web3j/web3j

  1. @Test
  2. public void testDecryptScrypt() throws Exception {
  3. WalletFile walletFile = load(SCRYPT);
  4. ECKeyPair ecKeyPair = Wallet.decrypt(PASSWORD, walletFile);
  5. assertThat(Numeric.toHexStringNoPrefix(ecKeyPair.getPrivateKey()), is(SECRET));
  6. }

代码示例来源:origin: web3j/web3j

  1. @Test
  2. public void testDecryptAes128Ctr() throws Exception {
  3. WalletFile walletFile = load(AES_128_CTR);
  4. ECKeyPair ecKeyPair = Wallet.decrypt(PASSWORD, walletFile);
  5. assertThat(Numeric.toHexStringNoPrefix(ecKeyPair.getPrivateKey()), is(SECRET));
  6. }

代码示例来源:origin: org.web3j/abi

  1. static String encodeBool(Bool value) {
  2. byte[] rawValue = new byte[MAX_BYTE_LENGTH];
  3. if (value.getValue()) {
  4. rawValue[rawValue.length - 1] = 1;
  5. }
  6. return Numeric.toHexStringNoPrefix(rawValue);
  7. }

代码示例来源:origin: org.web3j/abi

  1. static String encodeBytes(BytesType bytesType) {
  2. byte[] value = bytesType.getValue();
  3. int length = value.length;
  4. int mod = length % MAX_BYTE_LENGTH;
  5. byte[] dest;
  6. if (mod != 0) {
  7. int padding = MAX_BYTE_LENGTH - mod;
  8. dest = new byte[length + padding];
  9. System.arraycopy(value, 0, dest, 0, length);
  10. } else {
  11. dest = value;
  12. }
  13. return Numeric.toHexStringNoPrefix(dest);
  14. }

代码示例来源:origin: blockchain/unused-My-Wallet-V3-jar

  1. private static Boolean validateChecksumEthereumAddress(String address) {
  2. address = address.replace("0x", "");
  3. String hash = Numeric.toHexStringNoPrefix(Hash.sha3(address.toLowerCase().getBytes()));
  4. for (int i = 0; i < 40; i++) {
  5. if (Character.isLetter(address.charAt(i))) {
  6. // each uppercase letter should correlate with a first bit of 1 in the hash
  7. // char with the same index, and each lowercase letter with a 0 bit
  8. int charInt = Integer.parseInt(Character.toString(hash.charAt(i)), 16);
  9. if ((Character.isUpperCase(address.charAt(i)) && charInt <= 7)
  10. || (Character.isLowerCase(address.charAt(i)) && charInt > 7)) {
  11. return false;
  12. }
  13. }
  14. }
  15. return true;
  16. }
  17. }

代码示例来源:origin: io.daonomic.scalether/util

  1. private static String toHexStringZeroPadded(BigInteger value, int size, boolean withPrefix) {
  2. String result = toHexStringNoPrefix(value);
  3. int length = result.length();
  4. if (length > size) {
  5. throw new UnsupportedOperationException(
  6. "Value " + result + "is larger then length " + size);
  7. } else if (value.signum() < 0) {
  8. throw new UnsupportedOperationException("Value cannot be negative");
  9. }
  10. if (length < size) {
  11. result = Strings.zeros(size - length) + result;
  12. }
  13. if (withPrefix) {
  14. return HEX_PREFIX + result;
  15. } else {
  16. return result;
  17. }
  18. }

代码示例来源:origin: org.web3j/abi

  1. static String encodeNumeric(NumericType numericType) {
  2. byte[] rawValue = toByteArray(numericType);
  3. byte paddingValue = getPaddingValue(numericType);
  4. byte[] paddedRawValue = new byte[MAX_BYTE_LENGTH];
  5. if (paddingValue != 0) {
  6. for (int i = 0; i < paddedRawValue.length; i++) {
  7. paddedRawValue[i] = paddingValue;
  8. }
  9. }
  10. System.arraycopy(
  11. rawValue, 0,
  12. paddedRawValue, MAX_BYTE_LENGTH - rawValue.length,
  13. rawValue.length);
  14. return Numeric.toHexStringNoPrefix(paddedRawValue);
  15. }

代码示例来源:origin: org.web3j/abi

  1. Numeric.toHexStringNoPrefix(
  2. Numeric.toBytesPadded(
  3. new BigInteger(Long.toString(offset)), MAX_BYTE_LENGTH

相关文章