java.lang.Object
org.bouncycastle.util.Util
Utility class for byte array operations and cryptographic helper functions. Provides methods for cloning, concatenating, and comparing byte arrays.
Constructor Summary
ConstructorsMethod Summary
All MethodsModifier and TypeMethodDescriptionstatic 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 booleanconstantTimeAreEqual(byte[] a, byte[] b) Compare two arrays without leaking where they differ.
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 firstb- 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 extendb- 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 compareb- 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