Inheritance diagram for edu.virtualschool.jco.JCOPublicKey:


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.
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) | |
|
|
Construct key from Base64 encoded getEncoded() bytes.
Definition at line 48 of file JCOPublicKey.java.
00049 {
00050 this(JCOBase64.decode(input));
00051 }
|
|
|
Construct key from getEncoded() results (X.509)
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 }
|
|
|
Construct public key from RSAKeyParameters. Only used by JCOKeyPair
Definition at line 126 of file JCOPublicKey.java.
00127 {
00128 this.modulus = key.getModulus();
00129 this.publicExponent = key.getExponent();
00130 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|
|
|
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 }
|