/**
   * Changes hexadecimal to base 64
   *
   * @param hex the hexadecimal value to convert
   * @return the base64 value
   */
  public String HexToBase64(String hex) {

    byte[] byteArray = DatatypeConverter.parseHexBinary(hex);
    String base64String = DatatypeConverter.printBase64Binary(byteArray);

    return base64String;
  }
  @Test
  public void testCborSerialize() throws Exception {
    CBORAccessRequestMac instance = new CBORAccessRequestMac(this.publisherId, this.ifMapTimestamp);

    CborBuilder cb = new CborBuilder();
    ArrayBuilder ab = cb.addArray();

    instance.cborSerialize(ab);

    ab.end();

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    CborEncoder ce = new CborEncoder(bos);
    ce.encode(cb.build());

    log.info("CBOR serialize:");
    log.info(DatatypeConverter.printHexBinary(bos.toByteArray()));

    byte[] expResult =
        DatatypeConverter.parseHexBinary(
            "847839687474703A2F2F7777772E74727573746564636F6D707574696E6767726F75702E6F72672F32303130"
                + "2F49464D41504D455441444154412F32726163636573732D726571756573742D6D6163887269666D61702D7075626C69736865722D69646F6D792D7075626C6973"
                + "6865722D69646F69666D61702D74696D657374616D70C11A4ED9E8B2781869666D61702D74696D657374616D702D6672616374696F6EC482281A075BCA00716966"
                + "6D61702D63617264696E616C6974796B73696E676C6556616C756580");

    assertTrue(Arrays.equals(expResult, bos.toByteArray()));
  }
示例#3
0
 private void commonTests(Biscuit biscuit) throws GeneralSecurityException {
   String expectedMd5 = "748c617aaee4b9263761ed851769a314";
   for (String algo : new String[] {"none", "aesgcm256", "secretbox"}) {
     assertEquals("v-" + algo, biscuit.getString("k-" + algo));
     byte[] digest = MessageDigest.getInstance("MD5").digest(biscuit.get("k-" + algo + "-big"));
     assertArrayEquals(DatatypeConverter.parseHexBinary(expectedMd5), digest);
   }
 }
 private BsonDocument parseHexDocument(final BsonDocument document, final String hexDocument) {
   if (document.containsKey(hexDocument) && document.get(hexDocument).isDocument()) {
     byte[] bytes =
         DatatypeConverter.parseHexBinary(
             document.getDocument(hexDocument).getString("$hex").getValue());
     document.put(hexDocument, new BsonBinary(bytes));
   }
   return document;
 }
示例#5
0
 /**
  * 解密
  *
  * @param input hex形式的加密数据
  * @return 解密后字符串
  * @throws AESFailedException 输入字符串不合法或AES解密失败
  */
 public static String decrypt(String input) throws AESFailedException {
   try {
     byte[] val = DatatypeConverter.parseHexBinary(input);
     return new String(decrypt(SEED, val), "UTF-8");
   } catch (IllegalArgumentException e) {
     throw new AESFailedException(e);
   } catch (UnsupportedEncodingException e) {
     throw new AESFailedException(e);
   }
 }
示例#6
0
  /**
   * Metoda pretvara String koji sadrzi heksadekadski zapis u polje bitova
   *
   * @param keyText string s heksadekadskim zapisom
   * @return polje bajtova
   */
  public static byte[] hextobyte(String keyText) {

    /*int len = keyText.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(keyText.charAt(i), 16) << 4)
                             + Character.digit(keyText.charAt(i+1), 16));
    }*/
    // System.out.println(DatatypeConverter.parseHexBinary(keyText));
    return DatatypeConverter.parseHexBinary(keyText);
  }
 public static String extractTypeIdFromIOR(String url) {
   String ret = new String();
   byte data[] = DatatypeConverter.parseHexBinary(url.substring(4));
   if (data.length > 0) {
     // parse out type_id from IOR CDR encapsulation
     boolean bigIndian = !(data[0] > 0);
     int typeIdStringSize = readIntFromAlignedCDREncaps(data, 4, bigIndian);
     if (typeIdStringSize > 1) {
       ret = readStringFromAlignedCDREncaps(data, 8, typeIdStringSize - 1);
     }
   }
   return ret;
 }
示例#8
0
文件: ArpaUtil.java 项目: enom/rdap
 /**
  * parse IPV6 ARPA domain to IP bytes.
  *
  * @param name an ARPA string.
  * @return ARPA.
  */
 private static NetworkInBytes parseIpV6Arpa(String name) {
   LOGGER.debug("parseIp6Arpa, name:" + name);
   String arpa = StringUtils.removeEndIgnoreCase(name, CHAR_DOT + DomainUtil.IPV6_ARPA_SUFFIX);
   arpa = StringUtils.remove(arpa, CHAR_DOT);
   String ip = StringUtils.reverse(arpa);
   String fullIp = StringUtils.rightPad(ip, 32, '0');
   byte[] startIpBytes = DatatypeConverter.parseHexBinary(fullIp);
   int networkMask = StringUtils.length(arpa) * 4;
   IPv6Address fromByteArray = IPv6Address.fromByteArray(startIpBytes);
   IPv6Network network =
       IPv6Network.fromAddressAndMask(
           fromByteArray, IPv6NetworkMask.fromPrefixLength(networkMask));
   NetworkInBytes result =
       new NetworkInBytes(
           IpVersion.V6, network.getFirst().toByteArray(), network.getLast().toByteArray());
   return result;
 }
 public static String toBase64(final String hex) {
   return Base64.encode(DatatypeConverter.parseHexBinary(hex));
 }
 public static byte[] toByteArray(String s) {
   return DatatypeConverter.parseHexBinary(s);
 }
示例#11
0
 /**
  * @param line structured as SHA256;0000;size;YYYY-MM-DDTHH:MM:SS;name
  * @throws IllegalArgumentException
  */
 public FileInfo(String line) throws IllegalArgumentException {
   if (line == null) {
     throw new IllegalArgumentException("line must not be null");
   }
   String[] fields = line.split(";");
   if (fields.length < 5) {
     throw new IllegalArgumentException(
         String.format("line has %d fields instead of 5", fields.length));
   }
   byte[] hex = null;
   try {
     hex = DatatypeConverter.parseHexBinary(fields[0]);
   } catch (IllegalArgumentException e) {
     // exception handled below
   }
   if (hex == null || hex.length != HASH_BYTES) {
     throw new IllegalArgumentException(
         String.format("%s is not a valid SHA-256 signature", fields[0]));
   }
   hash = fields[0];
   int val = -1;
   try {
     val = Integer.parseInt(fields[1], 16);
   } catch (NumberFormatException e) {
     // exception handled below
   }
   if (val == -1 || fields[1].length() != 4) {
     throw new IllegalArgumentException(
         String.format("%s is not a valid 16 bit status", fields[1]));
   }
   flags = val;
   long len = -1;
   try {
     len = Long.parseLong(fields[2]);
   } catch (NumberFormatException e) {
     // exception handled below
   }
   if (len == -1) {
     throw new IllegalArgumentException(String.format("%s is not a valid size", fields[2]));
   }
   size = len;
   Instant instant = null;
   try {
     instant = Instant.parse(fields[3]);
   } catch (DateTimeParseException e) {
     // exception handled below
   }
   if (instant == null) {
     throw new IllegalArgumentException(String.format("%s is not a valid timestamp", fields[3]));
   }
   lastModif = FileTime.from(instant);
   StringBuffer finLigne = new StringBuffer(fields[4]);
   for (int i = 5; i < fields.length; i++) {
     finLigne.append(";").append(fields[i]);
   }
   if (finLigne.length() == 0) {
     throw new IllegalArgumentException(String.format("file name is empty"));
   }
   name = finLigne.toString();
   initialized = true;
 }
示例#12
0
  /**
   * Converts hexadecimal values to a byte array Used for bitwise operation
   *
   * @param hex the hexadecimal value to change
   * @return the byte array
   */
  public byte[] HexToByteArray(String hex) {

    byte[] byteArray = DatatypeConverter.parseHexBinary(hex);
    return byteArray;
  }
 public String getTotpSecretBase32() {
   byte[] bytes = DatatypeConverter.parseHexBinary(this.totpSecret);
   return new Base32().encodeAsString(bytes);
 }
 private byte[] parse(String hexString) {
   return DatatypeConverter.parseHexBinary(hexString.replaceAll(" ", ""));
 }
示例#15
0
 public static byte[] toVarBinary(String hex) {
   if (hex == null) {
     return null;
   }
   return DatatypeConverter.parseHexBinary(hex.replace("\n", ""));
 }