Class JsonWebKeyUtils

java.lang.Object
de.christofreichardt.json.webkey.JsonWebKeyUtils

public class JsonWebKeyUtils extends Object
Some low level utility procedures for handling raw bytes.
Author:
Christof Reichardt
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    alignBytes(byte[] bytes, int length)
    Takes the given raw bytes and tries to return an equivalent byte array with the favored length by skipping surplus zeroes or filling in missing zeroes.
    static byte[]
    fillMissingZeroes(byte[] bytes, int length)
    Fills in missing zeroes at the begin of a byte array if required.
    static String
    formatBytes(byte[] bytes)
    Interpretes the given bytes as unsigned integers and concatenates them into a comma separated string.
    static byte[]
    skipLeadingZeroes(byte[] bytes)
    Cuts leading zeroes from the beginning of the byte array.
    static byte[]
    skipSurplusZeroes(byte[] bytes, int length)
    Cuts surplus zeroes from the beginning of the byte array.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • formatBytes

      public static String formatBytes(byte[] bytes)
      Interpretes the given bytes as unsigned integers and concatenates them into a comma separated string.
      Parameters:
      bytes - the given raw bytes.
      Returns:
      a formatted string containf the bytes as comma separated unsigned integers.
    • skipSurplusZeroes

      public static byte[] skipSurplusZeroes(byte[] bytes, int length)
      Cuts surplus zeroes from the beginning of the byte array.
      Parameters:
      bytes - the given raw bytes.
      length - the favored length.
      Returns:
      a new byte array without surplus zeroes and the given minimal length.
    • skipLeadingZeroes

      public static byte[] skipLeadingZeroes(byte[] bytes)
      Cuts leading zeroes from the beginning of the byte array. A byte array made up exclusively of zeroes will be cut down to a single byte.
      Parameters:
      bytes - the given raw bytes.
      Returns:
      a byte array without leading zeroes.
    • fillMissingZeroes

      public static byte[] fillMissingZeroes(byte[] bytes, int length)
      Fills in missing zeroes at the begin of a byte array if required. An array of size greater than the given length remains untouched.
      Parameters:
      bytes - the given raw bytes.
      length - the favored length.
      Returns:
      a byte array with leading zeroes if required to match the favord length.
    • alignBytes

      public static byte[] alignBytes(byte[] bytes, int length)
      Takes the given raw bytes and tries to return an equivalent byte array with the favored length by skipping surplus zeroes or filling in missing zeroes. If that doesn't work an IllegalArgumentException is thrown.
      Parameters:
      bytes - the given raw bytes.
      length - the favored length.
      Returns:
      a byte array with the desired length.
      Throws:
      IllegalArgumentException - if the favored length couldn't be matched.