demo.cipher
Class MultipartEncryption
java.lang.Object
|
+--demo.cipher.MultipartEncryption
- public class MultipartEncryption
- extends Object
This class performs an automatic test of symmetric blockcipher algorithms implemented in the JCE MicroEdition. The test mainly aims
at the multipart encryption feature (i.e. cipher.update() calls followed by a finalising cipher.doFinal() call).
The testdata are generated dynamically for all modes of operation as well as for padding and no padding. Testdata for tests with
mode strings NOT containing PKCS5Padding are trimmed to fit to n*bcipherblocksize. Furthermore, all (secret)keys and initilisation vectors are generated automatically.
Test procedure:
- first generate random data for different: testdata, testdatasizes, keys, IV
- encrypt and save the results on a hashtable
- decrypt the encrypted data, compare it with the original input and store it on a hashtable
The hashtable is used for the comparision with the standard edition.
The testresults can be automatically checked against our standard library. To do so uncomment the required imports in the import section, the big block at the end of the class
and the line that invokes the method to start the comparision (serach for "uncomment").
After every cipher.update call a Result object containing the processed data, number of bytes processed and number of the update call is created. This object is stored
on a hashtable using transformation, keylength, testdatasize as key. After the same test is perfomed with the IAK-JCE library the testvalue is retrieved with the key and compared
Method Summary |
byte[] |
decrypt(Cipher cipher,
byte[] encryptedData,
Vector results)
Performs the actual decryption operation. |
byte[] |
encrypt(Cipher cipher,
byte[] inData,
Vector results)
Performs the actual encryption operation. |
protected byte[] |
generateTestData(int size)
Generates some random data. |
static void |
main(String[] args)
|
void |
printResults(Hashtable list)
Writes a list of Result objects to System.out. |
void |
start()
Entry method for TestAll. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
MultipartEncryption
public MultipartEncryption()
- Default constructor.
start
public void start()
- Entry method for TestAll.
encrypt
public byte[] encrypt(Cipher cipher,
byte[] inData,
Vector results)
throws IOException,
CryptoException
- Performs the actual encryption operation. The cipherobject has to be initialized before invoking this method.
- Parameters:
cipher
- the (pre-)initialized cipher objectinData
- the data to encryptoutData
- the encrypted data- Throws:
CryptoException
- IOException
-
decrypt
public byte[] decrypt(Cipher cipher,
byte[] encryptedData,
Vector results)
throws IOException,
CryptoException
- Performs the actual decryption operation. The cipherobject has to be initialized before invoking this method.
- Parameters:
cipher
- encryptedData
- - Returns:
-
- Throws:
IOException
- CryptoException
-
printResults
public void printResults(Hashtable list)
- Writes a list of Result objects to System.out. From the intermediate dataarray (at most) only the first 64 bytes are printed.
- Parameters:
list
- with results
main
public static void main(String[] args)
generateTestData
protected byte[] generateTestData(int size)
- Generates some random data.
- Parameters:
size
- number of random bytes to generate- Returns:
- bytearray with random bytes
IAIK-JCE ME 3.04, (c) 2002 IAIK, (c) 2003 to 2006 Stiftung SIC