All Packages Class Hierarchy This Package Previous Next Index
Class is.logi.crypto.Crypto
java.lang.Object
|
+----is.logi.crypto.Crypto
- public abstract class Crypto
- extends Object
This class contains numerous static and final utility functions
along with global variables for the logi.crypto package.
- Author:
- Logi Ragnarsson
(logir@hi.is)
-
BIT
- The binary digits "0" and "1".
-
cdsPath
- The array of names of packages that are searched for classes
mentioned in a CDS.
-
keySource
- The object used to store and retrieve keys.
-
NIBBLE
- The hexadecimal digits "0" through "f".
-
primeCertainty
- We allow a chance of 0.5**primeCertainty chance that given a composite
number, the primaility check will say it is a prime.
-
random
- This is the default random generator used by various Crypto
classes.
-
Crypto()
-
-
binString(int)
- Convert an int to a string of binary digits.
-
binString(long)
- Convert a long to a string of binary digits.
-
equal(byte[], byte[])
- Return true iff two array contain the same bytes.
-
equalRelaxed(byte[], byte[])
- Return true iff two arrays contain the same bytes, discounting
any zero bytes from the front of the arrays.
-
equalSub(byte[], int, byte[], int, int)
- Return true iff a sub-array of two arrays contain the same bytes.
-
fromHexNibble(char)
- Convert a hexadecimal digit to a byte.
-
fromHexString(String)
- Convert a string of hexadecimal digits to a byte array.
-
fromString(Reader)
- Parse the given Cipher Description String (CDS).
-
fromString(String)
- Parse the given Cipher Description String (CDS).
-
hexString(byte)
- Convert a byte to a string of hexadecimal digits.
-
hexString(byte[])
- Convert a byte array to a string of hexadecimal digits.
-
hexString(int)
- Convert an int to a string of hexadecimal digits.
-
hexString(long)
- Convert a long to a string of hexadecimal digits.
-
makeClass(String)
- Create a Class object for the named class.
-
makeInt(byte[], int, int)
- Convert a byte array to an int.
-
makeLong(byte[], int, int)
- Convert a byte array to a long.
-
makeSessionKey(String, byte[])
- Convert a byte array to a CipherKey.
-
pastSpace(Reader)
- Read characters from a Reader until a non-space character
is reached and return that character.
-
pickBits(int, byte[])
- Construct an int by picking bits from another int.
-
pickBits(long, byte[])
- Construct an long by picking bits from another long.
-
readInt(InputStream)
- Read an int from an InputStream in bigendian order.
-
writeBytes(int, byte[], int, int)
- Write an int to a byte array.
-
writeBytes(long, byte[], int, int)
- Write a long to a byte array.
-
writeInt(OutputStream, int)
- Write an int to an OutputStream in bigendian order.
random
public static Random random
- This is the default random generator used by various Crypto
classes. It should be a cryptographically secure
random number generator, preferably without any period, which
rules out all generators based on iterated functions, such as
java.util.Random.
If the file /dev/urandom
exists, random
is initialized to an instance of the RandomFromReader class
which read that file. Otherwise it is initialized to an instance
of the RandomSpinner class.
- See Also:
- RandomSpinner, RandomFromReader
primeCertainty
public static int primeCertainty
- We allow a chance of 0.5**primeCertainty chance that given a composite
number, the primaility check will say it is a prime. For complicated
reasons, the actual chance of generating a false prime is much
lower.
keySource
public static KeySource keySource
- The object used to store and retrieve keys.
It is used by the
lookup(fingerprint)
CDS.
NIBBLE
public static char NIBBLE[]
- The hexadecimal digits "0" through "f".
BIT
public static char BIT[]
- The binary digits "0" and "1".
cdsPath
public static String cdsPath[]
- The array of names of packages that are searched for classes
mentioned in a CDS.
Crypto
public Crypto()
makeLong
public static final long makeLong(byte buf[],
int i,
int length)
- Convert a byte array to a long. Bits are collected from
buf[i..i+length-1]
.
makeInt
public static final int makeInt(byte buf[],
int i,
int length)
- Convert a byte array to an int. Bits are collected from
buf[i..i+length-1]
.
writeBytes
public static final void writeBytes(long a,
byte dest[],
int i,
int length)
- Write a long to a byte array. Bits from
a
are written
to dest[i..i+length-1]
.
writeBytes
public static final void writeBytes(int a,
byte dest[],
int i,
int length)
- Write an int to a byte array. Bits from
a
are written
to dest[i..i+length-1]
.
pickBits
public static final int pickBits(int a,
byte bits[])
- Construct an int by picking bits from another int. The number in
bits[i]
is the index of the bit within a
that should be put at index i
in the result.
The most-significant bit is number 0.
pickBits
public static final long pickBits(long a,
byte bits[])
- Construct an long by picking bits from another long. The number in
bits[i]
is the index of the bit within a
that should be put at index i
in the result.
The most-significant bit is number 0.
hexString
public static final String hexString(byte buf[])
- Convert a byte array to a string of hexadecimal digits.
hexString
public static final String hexString(long a)
- Convert a long to a string of hexadecimal digits.
hexString
public static final String hexString(int a)
- Convert an int to a string of hexadecimal digits.
hexString
public static final String hexString(byte a)
- Convert a byte to a string of hexadecimal digits.
fromHexNibble
public static byte fromHexNibble(char n)
- Convert a hexadecimal digit to a byte.
fromHexString
public static byte[] fromHexString(String hex)
- Convert a string of hexadecimal digits to a byte array.
binString
public static final String binString(long a)
- Convert a long to a string of binary digits.
binString
public static final String binString(int a)
- Convert an int to a string of binary digits.
equal
public static boolean equal(byte a[],
byte b[])
- Return true iff two array contain the same bytes.
equalRelaxed
public static boolean equalRelaxed(byte a[],
byte b[])
- Return true iff two arrays contain the same bytes, discounting
any zero bytes from the front of the arrays.
equalSub
public static boolean equalSub(byte a[],
int i,
byte b[],
int j,
int length)
- Return true iff a sub-array of two arrays contain the same bytes.
Compares
a[i..i+length-1]
and b[j..j+length-1]
.
writeInt
public static final void writeInt(OutputStream out,
int x) throws IOException
- Write an int to an OutputStream in bigendian order.
readInt
public static final int readInt(InputStream in) throws IOException
- Read an int from an InputStream in bigendian order.
makeClass
public static Class makeClass(String name) throws InvalidCDSException
- Create a Class object for the named class. The class is searched
for in the packages named in the CDS Path, which by default
includes the appropriate logi.crypto package names.
- Throws: InvalidCDSException
- if the class could not be created
makeSessionKey
public static CipherKey makeSessionKey(String keyType,
byte bits[]) throws InvalidCDSException
- Convert a byte array to a CipherKey. Returns a new key of type
keyType
, with key-material from bits
.
keyType
should be the name of a class which implements
the CipherKey interface, such as "TriDESKey".
- Throws: InvalidCDSException
- if the key could not be created
pastSpace
public static int pastSpace(Reader r) throws IOException
- Read characters from a Reader until a non-space character
is reached and return that character.
fromString
public static Object fromString(Reader cds) throws InvalidCDSException, IOException
- Parse the given Cipher Description String (CDS).
This method can be used to parse a CDS such as that returned by
the Key and Fingerprint toString()
methods and return the
described object.
The CDS syntax is one of:
ClassName(parameters)
lookup(fingerprint)
ClassName
is the name of the class to generate. By default
the string "is.logi.crypto."
is prepended to the
class name and an instance created with the ClassName(String)
constructor. See the documentation for various classes for
details.
The lookup(fingerprint)
CDS assumes fingerprint
to be a CDS for a Fingerprint object. It then looks up the key with the
specified fingerprint in keySource
.
This method may throw exceptions with very long, nested explanations if
an exception occurs in a sub-CDS.
- Throws: IOException
- if an error occured reading characers from
in
- Throws: InvalidCDSException
- if the CDS is in some way malformed.
- See Also:
- keySource
fromString
public static Object fromString(String cds) throws InvalidCDSException
- Parse the given Cipher Description String (CDS). This method calls the
fromString(Reader)
method after wrapping th cds in a
StringReader.
- Throws: InvalidCDSException
- if the CDS is in some way malformed.
All Packages Class Hierarchy This Package Previous Next Index