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

edu.virtualschool.jco.JCOPublicKey Class Reference

Inheritance diagram for edu.virtualschool.jco.JCOPublicKey:

edu.virtualschool.jco.JCOAsymmetricKey edu.virtualschool.jco.JCOKey Collaboration diagram for edu.virtualschool.jco.JCOPublicKey:

Collaboration graph
[legend]
List of all members.

Detailed Description

The public half of a JCO Asymmetric key pair. The algorithm is RCA. The encoding format is X509.

Notice that keys do NOT implement equals() and are NOT serializable as in JCA/JCE. The combination makes obfuscation far more effective in hiding them.

Author:
bcox

Definition at line 38 of file JCOPublicKey.java.

Public Member Functions

 JCOPublicKey (String input) throws JCOFault
 JCOPublicKey (byte[] bytes) throws JCOFault
byte[] getEncoded ()
final String getAlgorithm ()
final String getFormat ()
final byte[] encryptBytes (byte[] inputBytes) throws JCOFault
final byte[] decryptBytes (byte[] inputBytes) throws JCOFault
final BigInteger getModulus ()
final BigInteger getPublicExponent ()
final JCOEncodedBytes encode ()
final Object verify (JCOSignedBytes signedObject) throws JCOSignatureFault, JCOFault
final AsymmetricKeyParameter getParameters ()

Package Functions

 JCOPublicKey (RSAKeyParameters key)


Constructor & Destructor Documentation

edu.virtualschool.jco.JCOPublicKey.JCOPublicKey String  input  )  throws JCOFault
 

Construct key from Base64 encoded getEncoded() bytes.

Parameters:
input - base64 encoding of getEncoded() output
Exceptions:
JCOFault 

Definition at line 48 of file JCOPublicKey.java.

00049   {
00050      this(JCOBase64.decode(input)); 
00051   }

edu.virtualschool.jco.JCOPublicKey.JCOPublicKey byte[]  bytes  )  throws JCOFault
 

Construct key from getEncoded() results (X.509)

Parameters:
bytes - results of calling getEncoded() on some JCOPublicKey
Exceptions:
JCOFault 

Definition at line 57 of file JCOPublicKey.java.

00058   {
00059     try
00060     {
00061       ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
00062       DERInputStream dis = new DERInputStream(bis);
00063       Object obj = dis.readObject();
00064       ASN1Sequence asn = (ASN1Sequence)obj;
00065       SubjectPublicKeyInfo ski = new SubjectPublicKeyInfo(asn);
00066       AlgorithmIdentifier algId = ski.getAlgorithmId();
00067       DERObject oid = algId.getObjectId();
00068         
00069        if (oid.equals(PKCSObjectIdentifiers.rsaEncryption))
00070        {
00071           ASN1Sequence asns = (ASN1Sequence)ski.getPublicKey();
00072           RSAPublicKeyStructure   pubKey = new RSAPublicKeyStructure(asns);
00073           this.modulus = pubKey.getModulus();
00074           this.publicExponent = pubKey.getPublicExponent();
00075        }
00076       else
00077         throw new RuntimeException("unexpected identifier: "+oid);
00078     }
00079     catch (IOException e)
00080     {
00081       throw new JCOFault(e, e);
00082     }
00083   }

edu.virtualschool.jco.JCOPublicKey.JCOPublicKey RSAKeyParameters  key  )  [package]
 

Construct public key from RSAKeyParameters. Only used by JCOKeyPair

Parameters:
key 

Definition at line 126 of file JCOPublicKey.java.

00127   {
00128       this.modulus = key.getModulus();
00129       this.publicExponent = key.getExponent();
00130   }


Member Function Documentation

final byte [] edu.virtualschool.jco.JCOPublicKey.decryptBytes byte[]  inputBytes  )  throws JCOFault [virtual]
 

Decrypt a byte array as produced by encryptBytes of the complimentary private key. Warning: SLOW. PKCS1 - private encrypt, public decrypt

Implements edu.virtualschool.jco.JCOAsymmetricKey.

Definition at line 159 of file JCOPublicKey.java.

00161   {
00162     AsymmetricBlockCipher cipher = new RSAEngine();
00163     PKCS1Encoding engine = new PKCS1Encoding(((PKCS1Encoding)cipher).getUnderlyingCipher());
00164     RSAKeyParameters key = new RSAKeyParameters(false, modulus, publicExponent);
00165     engine.init(false, key);
00166     try
00167     {
00168       return engine.processBlock(inputBytes, 0, inputBytes.length);
00169     }
00170     catch (InvalidCipherTextException e)
00171     {
00172       throw new JCOFault(e, e);
00173     }
00174   }

final JCOEncodedBytes edu.virtualschool.jco.JCOPublicKey.encode  ) 
 

Construct an encoded representation of this object suitable for disk storage.

Implements edu.virtualschool.jco.JCOKey.

Definition at line 183 of file JCOPublicKey.java.

References edu.virtualschool.jco.JCOPublicKey.getEncoded().

00184   {
00185     return new JCOEncodedBytes(getEncoded()); 
00186   }

final byte [] edu.virtualschool.jco.JCOPublicKey.encryptBytes byte[]  inputBytes  )  throws JCOFault [virtual]
 

Encrypt inputBytes such that they can only be decrypted by decryptBytes of the complimentary private key. Warning: this is slow. Only use when can't be avoided, such as for exchanging secret keys. OAEP - public encrypt, private decrypt

Implements edu.virtualschool.jco.JCOAsymmetricKey.

Definition at line 138 of file JCOPublicKey.java.

00140   {
00141     AsymmetricBlockCipher cipher = new RSAEngine();
00142     OAEPEncoding engine = new OAEPEncoding(((PKCS1Encoding)cipher).getUnderlyingCipher());
00143     RSAKeyParameters key = new RSAKeyParameters(false, modulus, publicExponent);
00144     engine.init(true, key);
00145     try
00146     {
00147       return engine.processBlock(inputBytes, 0, inputBytes.length);
00148     }
00149     catch (InvalidCipherTextException e)
00150     {
00151       throw new JCOFault(e, e);
00152     }
00153   }

final String edu.virtualschool.jco.JCOPublicKey.getAlgorithm  ) 
 

Returns the algorithm of the receiver, the constant string "RSA".

Implements edu.virtualschool.jco.JCOKey.

Definition at line 111 of file JCOPublicKey.java.

00112   {
00113     return "RSA"; 
00114   }

byte [] edu.virtualschool.jco.JCOPublicKey.getEncoded  ) 
 

Returns the X.509 encoding of the receiver.

Implements edu.virtualschool.jco.JCOKey.

Definition at line 87 of file JCOPublicKey.java.

Referenced by edu.virtualschool.jco.JCOPublicKey.encode().

00088   {
00089     ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
00090     DEROutputStream dOut = new DEROutputStream(bOut);
00091     DERObjectIdentifier oid = PKCSObjectIdentifiers.rsaEncryption;
00092     AlgorithmIdentifier aid = new AlgorithmIdentifier (oid, new DERNull());
00093     RSAPublicKeyStructure pks = new RSAPublicKeyStructure(modulus, publicExponent);
00094     DERObject der = pks.getDERObject();
00095 
00096     SubjectPublicKeyInfo info = new SubjectPublicKeyInfo(aid, der);
00097     try
00098     {
00099       dOut.writeObject(info);
00100       dOut.close();
00101       return bOut.toByteArray();
00102     }
00103     catch (IOException e)
00104     {
00105         throw new RuntimeFault(e, e);
00106     }
00107   }

final String edu.virtualschool.jco.JCOPublicKey.getFormat  ) 
 

Returns the encoding used by getEncoded, the string "X.509"

Implements edu.virtualschool.jco.JCOKey.

Definition at line 118 of file JCOPublicKey.java.

00119   {
00120     return "X.509";
00121   }


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