org.keyczar.util
Class Util

java.lang.Object
  extended by org.keyczar.util.Util

public class Util
extends java.lang.Object

A miscellaneous utility class. Includes random number generation, int-to-byte conversion, etc.

Author:
steveweis@gmail.com (Steve Weis)

Method Summary
static byte[] fromInt(int input)
          Returns a byte array containing 4 big-endian ordered bytes representing the given integer.
static byte[] fromLong(long input)
          Returns a byte array containing 8 big-endian ordered bytes representing the given long.
static com.google.gson.Gson gson()
           
static byte[] prefixHash(byte[]... inputs)
          Hashes a variable number of inputs and returns a new byte array
static void rand(byte[] dest)
          Write random bytes into the destination.
static byte[] rand(int len)
          Returns an array of random bytes of the given length
static int toInt(byte[] src)
          Converts a given byte array to an integer.
static long toLong(byte[] src)
          Converts a given byte array to a long.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

gson

public static com.google.gson.Gson gson()

fromInt

public static byte[] fromInt(int input)
Returns a byte array containing 4 big-endian ordered bytes representing the given integer.

Parameters:
input - The integer to convert to a byte array.
Returns:
A byte array representation of an integer.

fromLong

public static byte[] fromLong(long input)
Returns a byte array containing 8 big-endian ordered bytes representing the given long.

Parameters:
input - The long to convert to a byte array.
Returns:
A byte array representation of a long.

prefixHash

public static byte[] prefixHash(byte[]... inputs)
                         throws KeyczarException
Hashes a variable number of inputs and returns a new byte array

Parameters:
inputs - The inputs to hash
Returns:
The hash output
Throws:
KeyczarException - If the SHA-1 algorithm is not found

rand

public static void rand(byte[] dest)
Write random bytes into the destination. Uses pre-cached secure random objects

Parameters:
dest - Destionation to write the data

rand

public static byte[] rand(int len)
Returns an array of random bytes of the given length

Parameters:
len - The length of the random array to output
Returns:
A random array of bytes

toInt

public static int toInt(byte[] src)
Converts a given byte array to an integer. Reads the bytes in big-endian order. This method does not check the source array length.

Parameters:
src - A big-endian representation of an integer
Returns:
The integer value represented by the source array

toLong

public static long toLong(byte[] src)
Converts a given byte array to a long. Reads the bytes in big-endian order. This method does not check the source array length.

Parameters:
src - A big-endian representation of a long
Returns:
The long value represented by the source array