chapter3
Class Utils

java.lang.Object
  extended by chapter2.Utils
      extended by chapter3.Utils
Direct Known Subclasses:
Utils

public class Utils
extends Utils

General utilities for the third chapter examples.


Constructor Summary
Utils()
           
 
Method Summary
static javax.crypto.spec.IvParameterSpec createCtrIvForAES(int messageNumber, java.security.SecureRandom random)
          Create an IV suitable for using with AES in CTR mode.
static javax.crypto.SecretKey createKeyForAES(int bitLength, java.security.SecureRandom random)
          Create a key for use with AES.
static byte[] toByteArray(java.lang.String string)
          Convert the passed in String to a byte array by taking the bottom 8 bits of each character it contains.
static java.lang.String toString(byte[] bytes)
          Convert a byte array of 8 bit characters into a String.
static java.lang.String toString(byte[] bytes, int length)
          Convert a byte array of 8 bit characters into a String.
 
Methods inherited from class chapter2.Utils
toHex, toHex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

createKeyForAES

public static javax.crypto.SecretKey createKeyForAES(int bitLength,
                                                     java.security.SecureRandom random)
                                              throws java.security.NoSuchAlgorithmException,
                                                     java.security.NoSuchProviderException
Create a key for use with AES.

Parameters:
bitLength -
random -
Returns:
an AES key.
Throws:
java.security.NoSuchAlgorithmException
java.security.NoSuchProviderException

createCtrIvForAES

public static javax.crypto.spec.IvParameterSpec createCtrIvForAES(int messageNumber,
                                                                  java.security.SecureRandom random)
Create an IV suitable for using with AES in CTR mode.

The IV will be composed of 4 bytes of message number, 4 bytes of random data, and a counter of 8 bytes.

Parameters:
messageNumber - the number of the message.
random - a source of randomness
Returns:
an initialised IvParameterSpec

toString

public static java.lang.String toString(byte[] bytes,
                                        int length)
Convert a byte array of 8 bit characters into a String.

Parameters:
bytes - the array containing the characters
length - the number of bytes to process
Returns:
a String representation of bytes

toString

public static java.lang.String toString(byte[] bytes)
Convert a byte array of 8 bit characters into a String.

Parameters:
bytes - the array containing the characters
Returns:
a String representation of bytes

toByteArray

public static byte[] toByteArray(java.lang.String string)
Convert the passed in String to a byte array by taking the bottom 8 bits of each character it contains.

Parameters:
string - the string to be converted
Returns:
a byte array representation


Examples from "Beginning Cryptography with Java"