org.xipki.util.Hex类的使用及代码示例

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

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

Hex介绍

[英]TODO.
[中]待办事项。

代码示例

代码示例来源:origin: org.xipki/security

/**
 * Returns the hex representation of the bytes.
 *
 * @param bytes
 *          Data to be encoded. Must not be {@code null}.
 * @return the hex representation of the bytes.
 */
protected static String hex(byte[] bytes) {
 return Hex.encode(bytes);
}

代码示例来源:origin: org.xipki/security-pkcs11

/**
 * Returns the hex representation of the bytes.
 *
 * @param bytes
 *          Data to be encoded. Must not be {@code null}.
 * @return the hex representation of the bytes.
 */
protected static byte[] decodeHex(String hex) {
 return Hex.decode(hex);
}

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

public static String encode(byte[] bytes) {
 return new String(encodeToChars(bytes));
}

代码示例来源:origin: org.xipki/security-pkcs11

byte[] keyId = null;
if (str != null) {
 keyId = Hex.decode(str);
 String str2 = (keyId != null) ? "id " + Hex.encode(keyId) : "label " + keyLabel;
 throw new ObjectCreationException("cound not find identity with " + str2);

代码示例来源:origin: org.xipki/security-pkcs11

protected void assertNoIdentityAndCert(byte[] id, String label)
  throws P11DuplicateEntityException {
 if (id == null && label == null) {
  return;
 }
 Set<P11ObjectIdentifier> objectIds = new HashSet<>(identities.keySet());
 objectIds.addAll(certificates.keySet());
 for (P11ObjectIdentifier objectId : objectIds) {
  boolean matchId = (id == null) ? false : objectId.matchesId(id);
  boolean matchLabel = (label == null) ? false : label.equals(objectId.getLabel());
  if (matchId || matchLabel) {
   StringBuilder sb = new StringBuilder("Identity or Certificate with ");
   if (matchId) {
    sb.append("id=0x").append(Hex.encodeUpper(id));
    if (matchLabel) {
     sb.append(" and ");
    }
   }
   if (matchLabel) {
    sb.append("label=").append(label);
   }
   sb.append(" already exists");
   throw new P11DuplicateEntityException(sb.toString());
  }
 }
}

代码示例来源:origin: org.xipki/security

byte[] keyId = null;
if (str != null) {
 keyId = Hex.decode(str);
 String str2 = (keyId != null) ? "id " + Hex.encode(keyId) : "label " + keyLabel;
 throw new ObjectCreationException("cound not find identity with " + str2);

代码示例来源:origin: org.xipki/security

protected void assertNoIdentityAndCert(byte[] id, String label)
  throws P11DuplicateEntityException {
 if (id == null && label == null) {
  return;
 }
 Set<P11ObjectIdentifier> objectIds = new HashSet<>(identities.keySet());
 objectIds.addAll(certificates.keySet());
 for (P11ObjectIdentifier objectId : objectIds) {
  boolean matchId = (id == null) ? false : objectId.matchesId(id);
  boolean matchLabel = (label == null) ? false : label.equals(objectId.getLabel());
  if (matchId || matchLabel) {
   StringBuilder sb = new StringBuilder("Identity or Certificate with ");
   if (matchId) {
    sb.append("id=0x").append(Hex.encodeUpper(id));
    if (matchLabel) {
     sb.append(" and ");
    }
   }
   if (matchLabel) {
    sb.append("label=").append(label);
   }
   sb.append(" already exists");
   throw new P11DuplicateEntityException(sb.toString());
  }
 }
}

代码示例来源:origin: org.xipki/security-pkcs11

/**
 * Returns the hex representation of the bytes.
 *
 * @param bytes
 *          Data to be encoded. Must not be {@code null}.
 * @return the hex representation of the bytes.
 */
protected static String hex(byte[] bytes) {
 return Hex.encode(bytes);
}

代码示例来源:origin: org.xipki/security

/**
 * Returns the hex representation of the bytes.
 *
 * @param bytes
 *          Data to be encoded. Must not be {@code null}.
 * @return the hex representation of the bytes.
 */
protected static byte[] decodeHex(String hex) {
 return Hex.decode(hex);
}

代码示例来源:origin: org.xipki/util

public static String encode(byte[] bytes) {
 return new String(encodeToChars(bytes));
}

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

/**
 * Formats certificate serial number.
 * @param serialNumber certificate serial number
 * @return formatted certificate serial number
 */
public static String formatCsn(BigInteger serialNumber) {
 return "0x" + Hex.encode(serialNumber.toByteArray());
}

代码示例来源:origin: org.xipki/security

private static void addDigestPkcsPrefix(HashAlgo algo, String prefix) {
 digestPkcsPrefix.put(algo, Hex.decode(prefix));
}

代码示例来源:origin: org.xipki/util

/**
 * Formats certificate serial number.
 * @param serialNumber certificate serial number
 * @return formatted certificate serial number
 */
public static String formatCsn(BigInteger serialNumber) {
 return "0x" + Hex.encode(serialNumber.toByteArray());
}

代码示例来源:origin: org.xipki/util

public static byte[] decode(String hex) {
 return decode(hex.toCharArray());
}

代码示例来源:origin: org.xipki.shells/shell-base

private static String randomHex(int numOfBytes) {
 SecureRandom random = new SecureRandom();
 byte[] bytes = new byte[numOfBytes];
 random.nextBytes(bytes);
 return Hex.encode(bytes);
}

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

public static byte[] decode(String hex) {
 return decode(hex.toCharArray());
}

代码示例来源:origin: org.xipki/ocsp-client

private static String buildMessage(byte[] expected, byte[] is) {
 return StringUtil.concat("nonce unmatch (received ",
   (is == null || is.length == 0 ? "none" : Hex.encode(is)), ", but expected ",
   (expected == null || expected.length == 0 ? "none" : Hex.encode(expected)), ")");
}

代码示例来源:origin: org.xipki/ca-server

private static byte[] getTransactionIdBytes(String tid) throws OperationException {
 byte[] bytes = null;
 final int n = tid.length();
 if (n % 2 != 0) { // neither hex nor base64 encoded
  bytes = tid.getBytes();
 } else {
  try {
   bytes = Hex.decode(tid);
  } catch (Exception ex) {
   if (n % 4 == 0) {
    try {
     bytes = Base64.decode(tid);
    } catch (Exception ex2) {
     LOG.error("could not decode (hex or base64) '{}': {}", tid, ex2.getMessage());
    }
   }
  }
 }
 if (bytes == null) {
  bytes = tid.getBytes();
 }
 if (bytes.length > 20) {
  throw new OperationException(ErrorCode.BAD_REQUEST, "transactionID too long");
 }
 return bytes;
} // method getTransactionIdBytes

代码示例来源:origin: org.xipki.shell/shell-base

private static String randomHex(int numOfBytes) {
 SecureRandom random = new SecureRandom();
 byte[] bytes = new byte[numOfBytes];
 random.nextBytes(bytes);
 return Hex.encode(bytes);
}

代码示例来源:origin: org.xipki/security

public static String hexSha1(byte[] data) {
 return Hex.encode(hash(HashAlgo.SHA1, data, 0, data.length));
}

相关文章