gnu.java.security.util
Class Util
A collection of utility methods used throughout this project.
static String | byteToString(int n) - Returns a string of 2 hexadecimal digits (most significant digit first)
corresponding to the lowest 8 bits of
n .
|
static String | dump(BigInteger x) - Returns a hexadecimal dump of the trimmed bytes of a
BigInteger .
|
static String | dumpString(byte[] data)
|
static String | dumpString(byte[] data, int offset, int length)
|
static String | dumpString(byte[] data, int offset, int length, String m) - Dumps a byte array as a string, in a format that is easy to read for
debugging.
|
static String | dumpString(byte[] data, String m)
|
static byte[] | fromBase64(String str) - The inverse function of the above.
|
static int | fromDigit(char c) - Returns a number from
0 to 15 corresponding
to the designated hexadecimal digit.
|
static String | toBase64(byte[] buffer) - Converts a designated byte array to a Base-64 representation, with the
exceptions that (a) leading 0-byte(s) are ignored, and (b) the character
'.' (dot) shall be used instead of "+' (plus).
|
static byte[] | toBytesFromString(String s) -
Returns a byte array from a string of hexadecimal digits.
|
static byte[] | toBytesFromUnicode(String s)
|
static byte[] | toReversedBytesFromString(String s) - Returns a byte array from a string of hexadecimal digits, interpreting them
as a large big-endian integer and returning it as a large little-endian
integer.
|
static String | toReversedString(byte[] ba) - Returns a string of hexadecimal digits from a byte array.
|
static String | toReversedString(byte[] ba, int offset, int length) - Returns a string of hexadecimal digits from a byte array, starting at
offset and consisting of length bytes.
|
static String | toString(byte[] ba) - Returns a string of hexadecimal digits from a byte array.
|
static String | toString(byte[] ba, int offset, int length) - Returns a string of hexadecimal digits from a byte array, starting at
offset and consisting of length bytes.
|
static String | toString(int n) - Returns a string of 8 hexadecimal digits (most significant digit first)
corresponding to the unsigned integer
n .
|
static String | toString(int[] ia) - Returns a string of hexadecimal digits from an integer array.
|
static String | toString(long n) - Returns a string of 16 hexadecimal digits (most significant digit first)
corresponding to the unsigned long
n .
|
static String | toUnicodeString(byte[] ba) - Similar to the
toString() method except that the Unicode
escape character is inserted before every pair of bytes.
|
static String | toUnicodeString(byte[] ba, int offset, int length) - Similar to the
toString() method except that the Unicode
escape character is inserted before every pair of bytes.
|
static String | toUnicodeString(int[] ia) - Similar to the
toString() method except that the Unicode
escape character is inserted before every pair of bytes.
|
static byte[] | trim(BigInteger n) - Treats the input as the MSB representation of a number, and discards
leading zero elements.
|
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
byteToString
public static String byteToString(int n)
Returns a string of 2 hexadecimal digits (most significant digit first)
corresponding to the lowest 8 bits of n
.
n
- the byte value to convert.
- a string of 2 hex characters representing the input.
dumpString
public static String dumpString(byte[] data,
int offset,
int length,
String m)
Dumps a byte array as a string, in a format that is easy to read for
debugging. The string
m
is prepended to the start of each
line.
If
offset
and
length
are omitted, the whole
array is used. If
m
is omitted, nothing is prepended to each
line.
data
- the byte array to be dumped.offset
- the offset within data to start from.length
- the number of bytes to dump.m
- a string to be prepended to each line.
- a string containing the result.
fromBase64
public static final byte[] fromBase64(String str)
The inverse function of the above.
Converts a string representing the encoding of some bytes in Base-64 to
their original form.
str
- the Base-64 encoded representation of some byte(s).
- the bytes represented by the
str
.
fromDigit
public static int fromDigit(char c)
Returns a number from 0
to 15
corresponding
to the designated hexadecimal digit.
c
- a hexadecimal ASCII symbol.
toBase64
public static final String toBase64(byte[] buffer)
Converts a designated byte array to a Base-64 representation, with the
exceptions that (a) leading 0-byte(s) are ignored, and (b) the character
'.' (dot) shall be used instead of "+' (plus).
Used by SASL password file manipulation primitives.
buffer
- an arbitrary sequence of bytes to represent in Base-64.
- unpadded (without the '=' character(s)) Base-64 representation of
the input.
toBytesFromString
public static byte[] toBytesFromString(String s)
Returns a byte array from a string of hexadecimal digits.
s
- a string of hexadecimal ASCII characters
- the decoded byte array from the input hexadecimal string.
toReversedBytesFromString
public static byte[] toReversedBytesFromString(String s)
Returns a byte array from a string of hexadecimal digits, interpreting them
as a large big-endian integer and returning it as a large little-endian
integer.
s
- a string of hexadecimal ASCII characters
- the decoded byte array from the input hexadecimal string.
toReversedString
public static String toReversedString(byte[] ba)
Returns a string of hexadecimal digits from a byte array. Each byte is
converted to 2 hex symbols; zero(es) included. The argument is treated as a
large little-endian integer and is returned as a large big-endian integer.
This method calls the method with same name and three arguments as:
toReversedString(ba, 0, ba.length);
ba
- the byte array to convert.
- a string of hexadecimal characters (two for each byte) representing
the designated input byte array.
toReversedString
public static final String toReversedString(byte[] ba,
int offset,
int length)
Returns a string of hexadecimal digits from a byte array, starting at
offset
and consisting of
length
bytes. Each
byte is converted to 2 hex symbols; zero(es) included.
The byte array is treated as a large little-endian integer, and is returned
as a large big-endian integer.
ba
- the byte array to convert.offset
- the index from which to start considering the bytes to
convert.length
- the count of bytes, starting from the designated offset to
convert.
- a string of hexadecimal characters (two for each byte) representing
the designated input byte sub-array.
toString
public static String toString(byte[] ba)
Returns a string of hexadecimal digits from a byte array. Each byte is
converted to 2 hex symbols; zero(es) included.
This method calls the method with same name and three arguments as:
toString(ba, 0, ba.length);
ba
- the byte array to convert.
- a string of hexadecimal characters (two for each byte) representing
the designated input byte array.
toString
public static final String toString(byte[] ba,
int offset,
int length)
Returns a string of hexadecimal digits from a byte array, starting at
offset
and consisting of length
bytes. Each
byte is converted to 2 hex symbols; zero(es) included.
ba
- the byte array to convert.offset
- the index from which to start considering the bytes to
convert.length
- the count of bytes, starting from the designated offset to
convert.
- a string of hexadecimal characters (two for each byte) representing
the designated input byte sub-array.
toString
public static String toString(int n)
Returns a string of 8 hexadecimal digits (most significant digit first)
corresponding to the unsigned integer n
.
n
- the unsigned integer to convert.
- a hexadecimal string 8-character long.
toString
public static String toString(int[] ia)
Returns a string of hexadecimal digits from an integer array. Each int is
converted to 4 hex symbols.
toString
public static String toString(long n)
Returns a string of 16 hexadecimal digits (most significant digit first)
corresponding to the unsigned long n
.
n
- the unsigned long to convert.
- a hexadecimal string 16-character long.
toUnicodeString
public static String toUnicodeString(byte[] ba)
Similar to the toString()
method except that the Unicode
escape character is inserted before every pair of bytes. Useful to
externalise byte arrays that will be constructed later from such strings;
eg. s-box values.
toUnicodeString
public static final String toUnicodeString(byte[] ba,
int offset,
int length)
Similar to the toString()
method except that the Unicode
escape character is inserted before every pair of bytes. Useful to
externalise byte arrays that will be constructed later from such strings;
eg. s-box values.
toUnicodeString
public static String toUnicodeString(int[] ia)
Similar to the toString()
method except that the Unicode
escape character is inserted before every pair of bytes. Useful to
externalise integer arrays that will be constructed later from such
strings; eg. s-box values.
trim
public static final byte[] trim(BigInteger n)
Treats the input as the MSB representation of a number, and discards
leading zero elements. For efficiency, the input is simply returned if no
leading zeroes are found.
- the byte array representation of the designated
BigInteger
with no leading 0-bytes.
Util.java -- various utility routines.
Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
This file is a part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.