|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.cipher.Cipher
General purpose ciphering class.
Nested Class Summary | |
class |
Cipher.ByteArrayFilter
byte[] array filter implementation based on this cipher. |
static class |
Cipher.Error
Exception class for ciphering functions. |
Field Summary | |
static boolean |
DECRYPT
Decryption specifier for instantiation |
static sam.cipher.Cipher |
EMPTY
Empty cipher implementation, does nothing. |
static boolean |
ENCRYPT
Encryption specifier for instantiation |
static boolean |
INVERSE
Decryption specifier for instantiation |
protected sam.cipher.Key |
key
Actual key assigned to this cipher |
static sam.cipher.Registry |
REGISTRY
Central registry of all known cipher implementations. |
Constructor Summary | |
protected |
Cipher(sam.cipher.Key key)
Builds a new Cipher |
Method Summary | |
protected void |
cipher(byte[] data)
Deprecated. |
protected void |
cipher(byte[] data,
int offset,
sam.cipher.Key key)
Either encrypts or decrypts data according to the key direction. |
protected abstract void |
decrypt(byte[] data,
int offset,
sam.cipher.Key key)
Called in case of decrypting key |
protected abstract void |
encrypt(byte[] data,
int offset,
sam.cipher.Key key)
Called in case of encrypting key |
protected static void |
fill(byte[] data,
int start,
int end)
Called whenever the whole buffer can not be filled up with fresh data. |
protected int |
getPreferredSize(int size)
Specifiy preferred buffer size. |
static void |
main(java.lang.String[] args)
Tests all registered ciphers implementations. |
protected static void |
store(byte[] data,
int byteOffset,
int a)
Stores one int into the first 4 cells starting at byteOffset
of a byte[] array. |
protected static void |
store(byte[] data,
int byteOffset,
long a)
Stores one int into the first 4 cells starting at byteOffset
of a byte[] array. |
protected static void |
storeReversed(byte[] data,
int byteOffset,
long a)
Stores one long into the first 4 cells starting at byteOffset
of a byte[] array. |
static boolean |
streamTest(java.lang.String cipherName,
int length,
java.lang.String password)
Tests a cipher through the complete stream-based mechanism. |
protected boolean |
test()
Tests this cipher's implementation. |
protected static int |
unstoreInt(byte[] data,
int byteOffset)
Rebuilds one int from specified byte[] array starting at byteOffset . |
protected static long |
unstoreLong(byte[] data,
int byteOffset)
Rebuilds one long from specified byte[] array starting at byteOffset . |
protected static long |
unstoreReversedLong(byte[] data,
int byteOffset)
Rebuilds one long from specified byte[] array starting at byteOffset . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final boolean ENCRYPT
public static final boolean DECRYPT
public static final boolean INVERSE
public static final sam.cipher.Registry REGISTRY
protected final transient sam.cipher.Key key
public static final sam.cipher.Cipher EMPTY
Constructor Detail |
protected Cipher(sam.cipher.Key key)
Cipher
Key
Method Detail |
protected void cipher(byte[] data)
cipher
protected void cipher(byte[] data, int offset, sam.cipher.Key key)
Cipher.Key.direction
,
Cipher.encrypt
,
Cipher.decrypt
protected abstract void encrypt(byte[] data, int offset, sam.cipher.Key key)
protected abstract void decrypt(byte[] data, int offset, sam.cipher.Key key)
protected boolean test()
WarningNote that a cipher might be working even if this return false,
in particular in case of block/key size inconsistencies or inner Key
class.
However the cipher
is guaranteed to work properly if this returns true
public static boolean streamTest(java.lang.String cipherName, int length, java.lang.String password) throws java.io.IOException, java.lang.InterruptedException
cipherName
- the supposedly registered cipher to be testedlength
- the sample data lengthpassword
- the password to be used
java.io.IOException
java.lang.InterruptedException
public static void main(java.lang.String[] args)
java sam.cipher.Cipher [password] [cipher1 [cipher2 [...]]]
If none specified then all registered ciphers are used.
protected static void fill(byte[] data, int start, int end)
To be overriden as required.
This implementation fills up remaining bytes with random data.
protected int getPreferredSize(int size)
May return a fixed value, ignoring suggested size (e.g. return 16;
).
By default, this implementation simply returns its argument unchanged.
size
- proposed buffer size (in bytes)
protected static void store(byte[] data, int byteOffset, int a)
int
into the first 4
cells starting at byteOffset
of a byte[]
array.
protected static void store(byte[] data, int byteOffset, long a)
int
into the first 4
cells starting at byteOffset
of a byte[]
array.
protected static int unstoreInt(byte[] data, int byteOffset)
int
from specified byte[]
array starting at byteOffset
.
protected static long unstoreLong(byte[] data, int byteOffset)
long
from specified byte[]
array starting at byteOffset
.
protected static long unstoreReversedLong(byte[] data, int byteOffset)
long
from specified byte[]
array starting at byteOffset
.
protected static void storeReversed(byte[] data, int byteOffset, long a)
long
into the first 4
cells starting at byteOffset
of a byte[]
array.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |