|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.logi.crypto.Crypto
This class contains numerous static and final utility functions along with global variables for the logi.crypto package.
Field Summary | |
static char[] |
BIT
The binary digits "0" and "1". |
static java.lang.String[] |
cdsPath
The array of names of packages that are searched for classes mentioned in a CDS. |
static byte[] |
EMPTY_ARRAY
An empty byte array. |
static java.math.BigInteger |
FOUR
The constant four. |
static KeySource |
keySource
The object used to store and retrieve keys. |
static char[] |
NIBBLE
The hexadecimal digits "0" through "f". |
static java.math.BigInteger |
ONE
The constant one. |
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. |
static java.util.Random |
random
This is the default random generator used by various Crypto classes. |
static java.math.BigInteger |
TWO
The constant two. |
static java.math.BigInteger |
ZERO
The constant zero. |
Constructor Summary | |
Crypto()
|
Method Summary | |
static java.lang.String |
binString(int a)
Convert an int to a string of binary digits. |
static java.lang.String |
binString(long a)
Convert a long to a string of binary digits. |
static boolean |
equal(byte[] a,
byte[] b)
Return true iff two array contain the same bytes. |
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. |
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. |
static byte |
fromHexNibble(char n)
Convert a hexadecimal digit to a byte. |
static byte[] |
fromHexString(java.lang.String hex)
Convert a string of hexadecimal digits to a byte array. |
static java.lang.Object |
fromString(java.io.Reader cds)
Parse the given Cipher Description String (CDS). |
static java.lang.Object |
fromString(java.lang.String cds)
Parse the given Cipher Description String (CDS). |
static java.lang.String |
hexString(byte a)
Convert a byte to a string of hexadecimal digits. |
static java.lang.String |
hexString(byte[] buf)
Convert a byte array to a string of hexadecimal digits. |
static java.lang.String |
hexString(byte[] buf,
int i,
int length)
Convert a byte array to a string of hexadecimal digits. |
static java.lang.String |
hexString(int a)
Convert an int to a string of hexadecimal digits. |
static java.lang.String |
hexString(long a)
Convert a long to a string of hexadecimal digits. |
static void |
initRandom()
Initialize the logi.crypto library. |
static void |
initRandom(java.util.Random r)
Initialize the logi.crypto library. |
static java.lang.Class |
makeClass(java.lang.String name)
Create a Class object for the named class. |
static int |
makeInt(byte[] buf,
int i,
int length)
Convert a byte array to an int. |
static long |
makeLong(byte[] buf,
int i,
int length)
Convert a byte array to a long. |
static CipherKey |
makeSessionKey(java.lang.String keyType,
byte[] bits)
Convert a byte array to a CipherKey. |
static int |
pastSpace(java.io.Reader r)
Read characters from a Reader until a non-space character is reached and return that character. |
static int |
pickBits(int a,
byte[] bits)
Construct an int by picking bits from another int. |
static long |
pickBits(long a,
byte[] bits)
Construct an long by picking bits from another long. |
static int |
readBlock(java.io.InputStream in,
byte[] buf,
int i,
int len)
Reads a number of bytes, blocking until they are all available. |
static int |
readInt(java.io.InputStream in)
Read an int from an InputStream in bigendian order. |
static void |
writeBytes(int a,
byte[] dest,
int i,
int length)
Write an int to a byte array. |
static void |
writeBytes(long a,
byte[] dest,
int i,
int length)
Write a long to a byte array. |
static void |
writeInt(java.io.OutputStream out,
int x)
Write an int to an OutputStream in bigendian order. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static java.util.Random random
public static int primeCertainty
public static final java.math.BigInteger ZERO
public static final java.math.BigInteger ONE
public static final java.math.BigInteger TWO
public static final java.math.BigInteger FOUR
public static final byte[] EMPTY_ARRAY
public static KeySource keySource
lookup(fingerprint)
CDS.
public static char[] NIBBLE
public static char[] BIT
public static java.lang.String[] cdsPath
Constructor Detail |
public Crypto()
Method Detail |
public static void initRandom(java.util.Random r)
The random number generator used by various parts of the logi.crypto
library will be set to be the object specified in the
r
parameter.
RandomMD5
,
RandomFromStream
public static void initRandom()
This method will not do anything if one of the initRandom methods has been called previously.
The default random number generator will be used. If the file
/dev/urandom
can be read, this is an instance of the
RandomFromStream
class which reads that file.
Otherwise an instance of the RandomMD5
class is used.
RandomMD5
,
RandomFromStream
public static final long makeLong(byte[] buf, int i, int length)
buf[i..i+length-1]
.
public static final int makeInt(byte[] buf, int i, int length)
buf[i..i+length-1]
.
public static final void writeBytes(long a, byte[] dest, int i, int length)
a
are written
to dest[i..i+length-1]
.
public static final void writeBytes(int a, byte[] dest, int i, int length)
a
are written
to dest[i..i+length-1]
.
public static final int pickBits(int a, byte[] bits)
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.
public static final long pickBits(long a, byte[] bits)
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.
public static final java.lang.String hexString(byte[] buf)
public static final java.lang.String hexString(byte[] buf, int i, int length)
buf[i..i+length-1]
are used.
public static final java.lang.String hexString(long a)
public static final java.lang.String hexString(int a)
public static final java.lang.String hexString(byte a)
public static byte fromHexNibble(char n)
public static byte[] fromHexString(java.lang.String hex)
public static final java.lang.String binString(long a)
public static final java.lang.String binString(int a)
public static boolean equal(byte[] a, byte[] b)
public static boolean equalRelaxed(byte[] a, byte[] b)
public static boolean equalSub(byte[] a, int i, byte[] b, int j, int length)
a[i..i+length-1]
and b[j..j+length-1]
.
public static final void writeInt(java.io.OutputStream out, int x) throws java.io.IOException
java.io.IOException
public static final int readInt(java.io.InputStream in) throws java.io.IOException
java.io.IOException
public static final int readBlock(java.io.InputStream in, byte[] buf, int i, int len) throws java.io.IOException
java.io.IOException
public static java.lang.Class makeClass(java.lang.String name) throws InvalidCDSException
InvalidCDSException
- if the class could not be createdpublic static CipherKey makeSessionKey(java.lang.String keyType, byte[] bits) throws InvalidCDSException
keyType
, with key-material from bits
.
keyType
should be the name of a class which implements
the CipherKey interface, such as "TriDESKey".
InvalidCDSException
- if the key could not be createdpublic static int pastSpace(java.io.Reader r) throws java.io.IOException
java.io.IOException
public static java.lang.Object fromString(java.io.Reader cds) throws InvalidCDSException, java.io.IOException
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 "org.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.
java.io.IOException
- if an error occured reading characers from in
InvalidCDSException
- if the CDS is in some way malformed.keySource
public static java.lang.Object fromString(java.lang.String cds) throws InvalidCDSException
fromString(Reader)
method after wrapping th cds in a
StringReader.
InvalidCDSException
- if the CDS is in some way malformed.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |