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

edu.virtualschool.jco.JCOSignedBytes Class Reference

Inheritance diagram for edu.virtualschool.jco.JCOSignedBytes:

edu.virtualschool.jco.JCOGenericBytes Collaboration diagram for edu.virtualschool.jco.JCOSignedBytes:

Collaboration graph
[legend]
List of all members.

Detailed Description

Repository for the result of JCOAsymmetricKey signing operations.
Author:
bcox
See also:
JCOAsymmetricKey

JCOPublicKey

JCOPrivateKey

Definition at line 23 of file JCOSignedBytes.java.

Public Member Functions

 JCOSignedBytes (byte[] object, JCOAsymmetricKey signingKey) throws JCOFault
 JCOSignedBytes (Serializable object, JCOAsymmetricKey signingKey) throws JCOFault
final Object verify (JCOAsymmetricKey verificationKey) throws JCOSignatureFault, JCOFault
byte[] getSignature ()
String getAlgorithm ()
JCOEncodedBytes encode () throws JCOFault

Package Functions

final void signBytes (JCOAsymmetricKey signingKey) throws JCOFault

Package Attributes

byte[] signature
String algorithm

Static Package Attributes

final int SALT_LENGTH = 25
final long serialVersionUID = -5545654298242764588L


Constructor & Destructor Documentation

edu.virtualschool.jco.JCOSignedBytes.JCOSignedBytes byte[]  object,
JCOAsymmetricKey  signingKey
throws JCOFault
 

Construct a signed byte array.

Parameters:
object 
signingKey 
Exceptions:
JCOFault 

Definition at line 36 of file JCOSignedBytes.java.

References edu.virtualschool.jco.JCOSignedBytes.signBytes().

00038   {
00039     super(object);
00040     signBytes(signingKey);
00041   }

edu.virtualschool.jco.JCOSignedBytes.JCOSignedBytes Serializable  object,
JCOAsymmetricKey  signingKey
throws JCOFault
 

Construct a signed serializable object

Parameters:
object 
signingKey 
Exceptions:
JCOFault 

Definition at line 48 of file JCOSignedBytes.java.

References edu.virtualschool.jco.JCOSignedBytes.signBytes().

00050   {
00051     super(object);
00052     signBytes(signingKey);
00053   }


Member Function Documentation

byte [] edu.virtualschool.jco.JCOSignedBytes.getSignature  ) 
 

Return a clone of the receiver's signature.

Returns:
byte[] the cloned signature bytes

Definition at line 110 of file JCOSignedBytes.java.

00111   {
00112     byte[] sig = (byte[])this.signature.clone(); 
00113     return sig; 
00114   }

final void edu.virtualschool.jco.JCOSignedBytes.signBytes JCOAsymmetricKey  signingKey  )  throws JCOFault [package]
 

Internal utility used by constructors to sign the contents of the receiver's inherited byte array.

Parameters:
signingKey 
Exceptions:
JCOFault 

Definition at line 60 of file JCOSignedBytes.java.

Referenced by edu.virtualschool.jco.JCOSignedBytes.JCOSignedBytes().

00062   {
00063     try
00064     {
00065       SecureRandom random = new SecureRandom();
00066       PSSSigner eng = new PSSSigner(new RSAEngine(), new SHA1Digest(), SALT_LENGTH);
00067       eng.init(true, new ParametersWithRandom(signingKey.getParameters(), random));
00068       eng.update(bytes, 0, bytes.length);
00069       this.signature = eng.generateSignature();
00070     }
00071     catch (CryptoException e) { throw new JCOFault(e); }
00072     catch (DataLengthException e) { throw new JCOFault(e); }
00073   }

final Object edu.virtualschool.jco.JCOSignedBytes.verify JCOAsymmetricKey  verificationKey  )  throws JCOSignatureFault, JCOFault
 

Verify the signature of the receiver.

Parameters:
verificationKey 
Returns:
Object: the unsigned object
Exceptions:
JCOSignatureFault if verificationKey is not the complement of the signing key.
JCOFault on IOException (should not occur)

Definition at line 81 of file JCOSignedBytes.java.

00083   {
00084     try
00085     {
00086       RSAEngine engine = new RSAEngine();
00087       SHA1Digest digest = new SHA1Digest();
00088       PSSSigner signer =  new PSSSigner(engine, digest, SALT_LENGTH);
00089       signer.init(false, verificationKey.getParameters());
00090       signer.update(bytes, 0, bytes.length);
00091       boolean isValid = signer.verifySignature(this.signature);
00092 
00093       if (!isValid)
00094         throw new JCOSignatureFault("Signature verification failed. The verification key is not the complement of the signing key.");
00095 
00096       ByteArrayInputStream bis = new ByteArrayInputStream(this.bytes);
00097       ObjectInputStream oi = new ObjectInputStream(bis);
00098       Object obj = oi.readObject();
00099       bis.close();
00100       oi.close();
00101       return obj;
00102     }
00103     catch (IOException e) { throw new JCOFault(e); }
00104     catch (ClassNotFoundException e) { throw new JCOFault(e); }
00105   }


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