Package com.google.crypto.tink.subtle
Class Bytes
- java.lang.Object
-
- com.google.crypto.tink.subtle.Bytes
-
public final class Bytes extends java.lang.ObjectHelper methods that deal with byte arrays.- Since:
- 1.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intbyteArrayToInt(byte[] bytes)Transforms a passed LSB first byte array to an intstatic intbyteArrayToInt(byte[] bytes, int length)Transforms a passed LSB first byte array to an intstatic intbyteArrayToInt(byte[] bytes, int offset, int length)Transforms a passed LSB first byte array to an intstatic byte[]concat(byte[]... chunks)Returns the concatenation of the input arrays in a single array.static booleanequal(byte[] x, byte[] y)Best effort fix-timing array comparison.static byte[]intToByteArray(int capacity, int value)Transforms a passed value to a LSB first byte array with the size of the specified capacitystatic byte[]xor(byte[] x, byte[] y)Computes the xor of two byte arrays of equal size.static byte[]xor(byte[] x, int offsetX, byte[] y, int offsetY, int len)Computes the xor of two byte arrays, specifying offsets and the length to xor.static voidxor(java.nio.ByteBuffer output, java.nio.ByteBuffer x, java.nio.ByteBuffer y, int len)Computes the xor of two byte buffers, specifying the length to xor, and stores the result tooutput.static byte[]xorEnd(byte[] a, byte[] b)xors b to the end of a.
-
-
-
Method Detail
-
equal
public static final boolean equal(byte[] x, byte[] y)Best effort fix-timing array comparison.- Returns:
- true if two arrays are equal.
-
concat
public static byte[] concat(byte[]... chunks) throws java.security.GeneralSecurityExceptionReturns the concatenation of the input arrays in a single array. For example,concat(new byte[] {a, b}, new byte[] {}, new byte[] {c}returns the array{a, b, c}.- Returns:
- a single array containing all the values from the source arrays, in order
- Throws:
java.security.GeneralSecurityException
-
xor
public static final byte[] xor(byte[] x, int offsetX, byte[] y, int offsetY, int len)Computes the xor of two byte arrays, specifying offsets and the length to xor.- Returns:
- a new byte[] of length len.
-
xor
public static final void xor(java.nio.ByteBuffer output, java.nio.ByteBuffer x, java.nio.ByteBuffer y, int len)Computes the xor of two byte buffers, specifying the length to xor, and stores the result tooutput.
-
xor
public static final byte[] xor(byte[] x, byte[] y)Computes the xor of two byte arrays of equal size.- Returns:
- a new byte[] of length x.length.
-
xorEnd
public static final byte[] xorEnd(byte[] a, byte[] b)xors b to the end of a.- Returns:
- a new byte[] of length x.length.
-
intToByteArray
public static byte[] intToByteArray(int capacity, int value)Transforms a passed value to a LSB first byte array with the size of the specified capacity- Parameters:
capacity- size of the resulting byte arrayvalue- that should be represented as a byte array. 0 <= value < 256^capacity.
-
byteArrayToInt
public static int byteArrayToInt(byte[] bytes)
Transforms a passed LSB first byte array to an int- Parameters:
bytes- that should be transformed to a byte array
-
byteArrayToInt
public static int byteArrayToInt(byte[] bytes, int length)Transforms a passed LSB first byte array to an int- Parameters:
bytes- that should be transformed to a byte arraylength- amount of the passedbytesthat should be transformed
-
byteArrayToInt
public static int byteArrayToInt(byte[] bytes, int offset, int length)Transforms a passed LSB first byte array to an int- Parameters:
bytes- that should be transformed to a byte arrayoffset- start index to start the transformationlength- amount of the passedbytesthat should be transformed
-
-