Top Description Fields Constructors Methods
org.bouncycastle.pqc.legacy.math.linearalgebra

public final Class ByteUtils

extends Object
Class Inheritance
Imports
org.bouncycastle.util.Strings

Deprecated

use org.bouncycastle.util.Arrays.

This class is a utility class for manipulating byte arrays.

Field Summary

Modifier and TypeField and Description
private static final char[]

Constructor Summary

AccessConstructor and Description
private
ByteUtils()

Default constructor (private)

Method Summary

Modifier and TypeMethod and Description
public static byte[]

Returns:

the clone of the given array, or null if the array is null
clone
(byte[]
the array to clone
array
)

Return a clone of the given byte array (performs null check beforehand).

public static byte[]

Returns:

(x2 | | x1) (little-endian order, i.e. x1 is at lower memory addresses)
concatenate
(byte[]
the first array
x1
,
byte[]
the second array
x2
)

Concatenate two byte arrays.

public static byte[]

Returns:

the concatenated input array
concatenate
(byte[][]
a 2-dimensional byte array
array
)

Convert a 2-dimensional byte array into a 1-dimensional byte array by concatenating all entries.

public static int

Returns:

the hashcode
deepHashCode
(byte[]
the array to compute the hashcode of
array
)

Computes a hashcode based on the contents of a one-dimensional byte array rather than its identity.

public static int

Returns:

the hashcode
deepHashCode
(byte[][]
the array to compute the hashcode of
array
)

Computes a hashcode based on the contents of a two-dimensional byte array rather than its identity.

public static int

Returns:

the hashcode
deepHashCode
(byte[][][]
the array to compute the hashcode of
array
)

Computes a hashcode based on the contents of a three-dimensional byte array rather than its identity.

public static boolean

Returns:

the result of the comparison
equals
(byte[]
the first byte array
left
,
byte[]
the second byte array
right
)

Compare two byte arrays (perform null checks beforehand).

public static boolean

Returns:

the result of the comparison
equals
(byte[][]
the first byte array
left
,
byte[][]
the second byte array
right
)

Compare two two-dimensional byte arrays.

public static boolean

Returns:

the result of the comparison
equals
(byte[][][]
the first byte array
left
,
byte[][][]
the second byte array
right
)

Compare two three-dimensional byte arrays.

public static byte[]

Returns:

a byte array with the corresponding value
fromHexString
(String
a hex string
s
)

Convert a string containing hexadecimal characters to a byte-array.

public static byte[][]

Returns:

the splitted input array as an array of two byte arrays
split
(byte[]
the byte array to be split
input
,
int
the index where the byte array is split
index
)

Split a byte array input into two arrays at index, i.e. the first array will have the lower index bytes, the second one the higher input.length - index bytes.

public static byte[]

Returns:

a subarray of input, ranging from start (inclusively) to end (exclusively)
subArray
(byte[]
the input byte array
input
,
int
the start index
start
,
int
the end index
end
)

Generate a subarray of a given byte array.

public static byte[]

Returns:

a subarray of input, ranging from start to the end of the array
subArray
(byte[]
the input byte array
input
,
int
the start index
start
)

Generate a subarray of a given byte array.

public static String

Returns:

the corresponding bit string
toBinaryString
(byte[]
the byte array to be converted
input
)

Convert a byte array to the corresponding bit string.

public static char[]

Returns:

char array
toCharArray
(byte[]
- the byte array
input
)

Rewrite a byte array as a char array

public static String

Returns:

the corresponding hexstring
toHexString
(byte[]
the byte array to be converted
input
)

Convert a byte array to the corresponding hexstring.

public static String

Returns:

the corresponding hex string
toHexString
(byte[]
the byte array to be converted
input
,
String
the prefix to put at the beginning of the hex string
prefix
,
String
a separator string
seperator
)

Convert a byte array to the corresponding hex string.

public static byte[]

Returns:

x1 XOR x2
xor
(byte[]
the first array
x1
,
byte[]
the second array
x2
)

Compute the bitwise XOR of two arrays of bytes.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

HEX_CHARSback to summary
private static final char[] HEX_CHARS

Constructor Detail

ByteUtilsback to summary
private ByteUtils()

Default constructor (private)

Method Detail

cloneback to summary
public static byte[] clone(byte[] array)

Return a clone of the given byte array (performs null check beforehand).

Parameters
array:byte[]

the array to clone

Returns:byte[]

the clone of the given array, or null if the array is null

concatenateback to summary
public static byte[] concatenate(byte[] x1, byte[] x2)

Concatenate two byte arrays. No null checks are performed.

Parameters
x1:byte[]

the first array

x2:byte[]

the second array

Returns:byte[]

(x2 | | x1) (little-endian order, i.e. x1 is at lower memory addresses)

concatenateback to summary
public static byte[] concatenate(byte[][] array)

Convert a 2-dimensional byte array into a 1-dimensional byte array by concatenating all entries.

Parameters
array:byte[][]

a 2-dimensional byte array

Returns:byte[]

the concatenated input array

deepHashCodeback to summary
public static int deepHashCode(byte[] array)

Computes a hashcode based on the contents of a one-dimensional byte array rather than its identity.

Parameters
array:byte[]

the array to compute the hashcode of

Returns:int

the hashcode

deepHashCodeback to summary
public static int deepHashCode(byte[][] array)

Computes a hashcode based on the contents of a two-dimensional byte array rather than its identity.

Parameters
array:byte[][]

the array to compute the hashcode of

Returns:int

the hashcode

deepHashCodeback to summary
public static int deepHashCode(byte[][][] array)

Computes a hashcode based on the contents of a three-dimensional byte array rather than its identity.

Parameters
array:byte[][][]

the array to compute the hashcode of

Returns:int

the hashcode

equalsback to summary
public static boolean equals(byte[] left, byte[] right)

Compare two byte arrays (perform null checks beforehand).

Parameters
left:byte[]

the first byte array

right:byte[]

the second byte array

Returns:boolean

the result of the comparison

equalsback to summary
public static boolean equals(byte[][] left, byte[][] right)

Compare two two-dimensional byte arrays. No null checks are performed.

Parameters
left:byte[][]

the first byte array

right:byte[][]

the second byte array

Returns:boolean

the result of the comparison

equalsback to summary
public static boolean equals(byte[][][] left, byte[][][] right)

Compare two three-dimensional byte arrays. No null checks are performed.

Parameters
left:byte[][][]

the first byte array

right:byte[][][]

the second byte array

Returns:boolean

the result of the comparison

fromHexStringback to summary
public static byte[] fromHexString(String s)

Convert a string containing hexadecimal characters to a byte-array.

Parameters
s:String

a hex string

Returns:byte[]

a byte array with the corresponding value

splitback to summary
public static byte[][] split(byte[] input, int index) throws ArrayIndexOutOfBoundsException

Split a byte array input into two arrays at index, i.e. the first array will have the lower index bytes, the second one the higher input.length - index bytes.

Parameters
input:byte[]

the byte array to be split

index:int

the index where the byte array is split

Returns:byte[][]

the splitted input array as an array of two byte arrays

Exceptions
ArrayIndexOutOfBoundsException:
if index is out of bounds
subArrayback to summary
public static byte[] subArray(byte[] input, int start, int end)

Generate a subarray of a given byte array.

Parameters
input:byte[]

the input byte array

start:int

the start index

end:int

the end index

Returns:byte[]

a subarray of input, ranging from start (inclusively) to end (exclusively)

subArrayback to summary
public static byte[] subArray(byte[] input, int start)

Generate a subarray of a given byte array.

Parameters
input:byte[]

the input byte array

start:int

the start index

Returns:byte[]

a subarray of input, ranging from start to the end of the array

toBinaryStringback to summary
public static String toBinaryString(byte[] input)

Convert a byte array to the corresponding bit string.

Parameters
input:byte[]

the byte array to be converted

Returns:String

the corresponding bit string

toCharArrayback to summary
public static char[] toCharArray(byte[] input)

Rewrite a byte array as a char array

Parameters
input:byte[]

- the byte array

Returns:char[]

char array

toHexStringback to summary
public static String toHexString(byte[] input)

Convert a byte array to the corresponding hexstring.

Parameters
input:byte[]

the byte array to be converted

Returns:String

the corresponding hexstring

toHexStringback to summary
public static String toHexString(byte[] input, String prefix, String seperator)

Convert a byte array to the corresponding hex string.

Parameters
input:byte[]

the byte array to be converted

prefix:String

the prefix to put at the beginning of the hex string

seperator:String

a separator string

Returns:String

the corresponding hex string

xorback to summary
public static byte[] xor(byte[] x1, byte[] x2)

Compute the bitwise XOR of two arrays of bytes. The arrays have to be of same length. No length checking is performed.

Parameters
x1:byte[]

the first array

x2:byte[]

the second array

Returns:byte[]

x1 XOR x2