Package net.schmizz.sshj.common
Class ByteArrayUtils
- java.lang.Object
-
- net.schmizz.sshj.common.ByteArrayUtils
-
public class ByteArrayUtils extends java.lang.Object
Utility functions for byte arrays.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static char[]
digits
-
Constructor Summary
Constructors Constructor Description ByteArrayUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
encodeSensitiveStringToUtf8(char[] str)
Converts a char-array to UTF-8 byte-array and then blanks out source array and all intermediate arrays.static boolean
equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length)
Check whether some part or whole of two byte arrays is equal, forlength
bytes starting at some offset.static byte[]
parseHex(java.lang.String hex)
private static int
parseHexDigit(char c)
static java.lang.String
printHex(byte[] array, int offset, int len)
Get a hexadecimal representation of a byte array starting atoffset
index forlen
bytes, with each octet separated by a space.static java.lang.String
toHex(byte[] array)
Get the hexadecimal representation of a byte array.static java.lang.String
toHex(byte[] array, int offset, int len)
Get the hexadecimal representation of a byte array starting atoffset
index forlen
bytes.
-
-
-
Method Detail
-
equals
public static boolean equals(byte[] a1, int a1Offset, byte[] a2, int a2Offset, int length)
Check whether some part or whole of two byte arrays is equal, forlength
bytes starting at some offset.- Parameters:
a1
-a1Offset
-a2
-a2Offset
-length
-- Returns:
true
orfalse
-
printHex
public static java.lang.String printHex(byte[] array, int offset, int len)
Get a hexadecimal representation of a byte array starting atoffset
index forlen
bytes, with each octet separated by a space.- Parameters:
array
-offset
-len
-- Returns:
- hex string, each octet delimited by a space
-
toHex
public static java.lang.String toHex(byte[] array)
Get the hexadecimal representation of a byte array.- Parameters:
array
-- Returns:
- hex string
-
toHex
public static java.lang.String toHex(byte[] array, int offset, int len)
Get the hexadecimal representation of a byte array starting atoffset
index forlen
bytes.- Parameters:
array
-offset
-len
-- Returns:
- hex string
-
parseHex
public static byte[] parseHex(java.lang.String hex)
-
parseHexDigit
private static int parseHexDigit(char c)
-
encodeSensitiveStringToUtf8
public static byte[] encodeSensitiveStringToUtf8(char[] str)
Converts a char-array to UTF-8 byte-array and then blanks out source array and all intermediate arrays. This is useful when a plaintext password needs to be encoded as UTF-8.- Parameters:
str
- A not-null string as a character array.- Returns:
- UTF-8 bytes of the string
-
-