java.lang.Object
org.bouncycastle.util.Util

public class Utilextends Object
Utility class for byte array operations and cryptographic helper functions. Provides methods for cloning, concatenating, and comparing byte arrays.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Every helper below is static, so an instance carries nothing.
  • Method Summary

    All Methods
    Modifier and Type
    Method
    Description
    static byte[]
    append(byte[] a, byte b)
    Extend an array by one byte at the end.
    static byte[]
    clone(byte[] a)
    Copy an array into an independent one.
    static byte[]
    concatenate(byte[][] arrays)
    Join several arrays back to back into a new one.
    static byte[]
    concatenate(byte[] a, byte[] b)
    Join two arrays back to back into a new one.
    static boolean
    constantTimeAreEqual(byte[] a, byte[] b)
    Compare two arrays without leaking where they differ.

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Util

      public Util()
      Every helper below is static, so an instance carries nothing.
  • Method Details

    • clone

      public static byte[] clone(byte[] a)
      Copy an array into an independent one.
      Parameters:
      a - the array to copy
      Returns:
      an independent copy of the array
    • concatenate

      public static byte[] concatenate(byte[][] arrays)
      Join several arrays back to back into a new one.
      Parameters:
      arrays - the arrays to join, in order
      Returns:
      a new array holding every input array back to back
    • concatenate

      public static byte[] concatenate(byte[] a, byte[] b)
      Join two arrays back to back into a new one.
      Parameters:
      a - the array placed first
      b - the array placed second
      Returns:
      a new array holding a followed by b
    • append

      public static byte[] append(byte[] a, byte b)
      Extend an array by one byte at the end.
      Parameters:
      a - the array to extend
      b - the byte to place in the new last position
      Returns:
      a new array holding a followed by b
    • constantTimeAreEqual

      public static boolean constantTimeAreEqual(byte[] a, byte[] b)
      Compare two arrays without leaking where they differ.
      Parameters:
      a - the first array to compare
      b - the second array to compare
      Returns:
      true if the two arrays hold the same bytes in the same order; arrays of different lengths are never equal