/** * 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); }
/** * 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); }
public static String encode(byte[] bytes) { return new String(encodeToChars(bytes)); }
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()); } } }
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()); } } }
/** * 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); }
/** * 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); }
public static String encode(byte[] bytes) { return new String(encodeToChars(bytes)); }
/** * 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()); }
private static void addDigestPkcsPrefix(HashAlgo algo, String prefix) { digestPkcsPrefix.put(algo, Hex.decode(prefix)); }
/** * 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()); }
public static byte[] decode(String hex) { return decode(hex.toCharArray()); }
private static String randomHex(int numOfBytes) { SecureRandom random = new SecureRandom(); byte[] bytes = new byte[numOfBytes]; random.nextBytes(bytes); return Hex.encode(bytes); }
public static byte[] decode(String hex) { return decode(hex.toCharArray()); }
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
private static String randomHex(int numOfBytes) { SecureRandom random = new SecureRandom(); byte[] bytes = new byte[numOfBytes]; random.nextBytes(bytes); return Hex.encode(bytes); }
public static String hexSha1(byte[] data) { return Hex.encode(hash(HashAlgo.SHA1, data, 0, data.length)); }