Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

edu.virtualschool.jco.JCOSecretKey Class Reference

Inheritance diagram for edu.virtualschool.jco.JCOSecretKey:

edu.virtualschool.jco.JCOSymmetricKey edu.virtualschool.jco.JCOKey Collaboration diagram for edu.virtualschool.jco.JCOSecretKey:

Collaboration graph
[legend]
List of all members.

Detailed Description

JCOSecretKeys are SymmetricKeys implemented with the RC4 algorithm, a stream cipher in which encryption modes padding, and blocks are not needed. By default the key length is 128 bits (via the noargs constructor) but a constructor is available for creating keys of any length that BouncyCastle supports, currently 40 to 2048. The encoding format is RAW.

Notice that keys do NOT override Object.equals() and are NOT serializable as in JCA/JCE. The combination makes obfuscation far more effective at hiding them. To save/restore them in files, use the encode() or getEncoded() methods.

Ref: http://wireless.java.sun.com/midp/articles/security4/

Author:
bcox

Definition at line 26 of file JCOSecretKey.java.

Public Member Functions

 JCOSecretKey ()
 JCOSecretKey (int keyLengthInBytes) throws RuntimeFault
 JCOSecretKey (String string)
 JCOSecretKey (byte[] bytes)
final byte[] decryptBytes (byte[] inputBytes)
final byte[] encryptBytes (byte[] inputBytes)
final String getAlgorithm ()
final String getFormat ()

Static Package Functions

final KeyParameter makeKeyParameter (int keyLengthInBytes) throws RuntimeFault

Static Package Attributes

final int DEFAULT_KEY_LENGTH = 128/8
 Default key length in bytes.

final int MINIMUM_KEY_LENGTH = 40/8
final int MAXIMUM_KEY_LENGTH = 2048/8


Constructor & Destructor Documentation

edu.virtualschool.jco.JCOSecretKey.JCOSecretKey  ) 
 

Construct a secret key with the default length (16 bytes = 128 bites) from SecureRandom bytes.

Definition at line 37 of file JCOSecretKey.java.

References edu.virtualschool.jco.JCOSecretKey.DEFAULT_KEY_LENGTH.

00038   {
00039     super(makeKeyParameter(DEFAULT_KEY_LENGTH));
00040   }

edu.virtualschool.jco.JCOSecretKey.JCOSecretKey int  keyLengthInBytes  )  throws RuntimeFault
 

Constructor for artibritary key lengths between 40 and 2048.

Exceptions:
RuntimeFault if key lengths <40 or >2048 bits are requested.
Parameters:
keyLengthInBytes - the desired key length in bytes (bits * 8)

Definition at line 46 of file JCOSecretKey.java.

00047   {
00048     super(makeKeyParameter(keyLengthInBytes));
00049   }

edu.virtualschool.jco.JCOSecretKey.JCOSecretKey String  string  ) 
 

Construct an instance from the Base64-encoded argument. This should be the result of calling getEncoded() on a valid instance. (Not sure what RAW encoding means or how it might go wrong at this point, so don't expect this to hold up to devient use cases). This constructor is particularly useful for generating secret keys from hard-coded string initializers.

Parameters:
string 

Definition at line 69 of file JCOSecretKey.java.

00070   {
00071     this(JCOBase64.decode(string));
00072   }

edu.virtualschool.jco.JCOSecretKey.JCOSecretKey byte[]  bytes  ) 
 

Construct an instance from the provided byte array, which should contain bytes produced by getEncoded().

Parameters:
bytes 

Definition at line 78 of file JCOSecretKey.java.

00079   {
00080     super(new KeyParameter(bytes));
00081   }


Member Function Documentation

final byte [] edu.virtualschool.jco.JCOSecretKey.decryptBytes byte[]  inputBytes  )  [virtual]
 

Encrypt (or decrypt) the provided inputBytes.

Implements edu.virtualschool.jco.JCOSymmetricKey.

Definition at line 85 of file JCOSecretKey.java.

Referenced by edu.virtualschool.jco.JCOSecretKey.encryptBytes().

00086   {
00087     RC4Engine engine = new RC4Engine();
00088     engine.init(true, key);
00089     byte[]  outputBytes = new byte[inputBytes.length];
00090     engine.processBytes(inputBytes, 0, inputBytes.length, outputBytes, 0);
00091     return outputBytes;
00092   }

final byte [] edu.virtualschool.jco.JCOSecretKey.encryptBytes byte[]  inputBytes  )  [virtual]
 

Encryption is complimentary with decryption.

Implements edu.virtualschool.jco.JCOSymmetricKey.

Definition at line 96 of file JCOSecretKey.java.

References edu.virtualschool.jco.JCOSecretKey.decryptBytes().

00097   {
00098     return decryptBytes(inputBytes);
00099   }

final String edu.virtualschool.jco.JCOSecretKey.getAlgorithm  )  [virtual]
 

Returns the constant string "RC4"

Implements edu.virtualschool.jco.JCOSymmetricKey.

Definition at line 103 of file JCOSecretKey.java.

00104   {
00105     return "RC4"; 
00106   }

final String edu.virtualschool.jco.JCOSecretKey.getFormat  )  [virtual]
 

Returns the constant string "RAW" signifying RAW encoding (whatever that means; I'm not really sure).

Implements edu.virtualschool.jco.JCOSymmetricKey.

Definition at line 111 of file JCOSecretKey.java.

00112   {
00113     return "RAW";
00114   }


The documentation for this class was generated from the following file: