01: package org.bouncycastle.bcpg;
02:
03: import java.math.BigInteger;
04: import java.io.*;
05:
06: /**
07: * base class for an RSA Public Key.
08: */
09: public class RSAPublicBCPGKey extends BCPGObject implements BCPGKey {
10: MPInteger n;
11: MPInteger e;
12:
13: /**
14: * Construct an RSA public key from the passed in stream.
15: *
16: * @param in
17: * @throws IOException
18: */
19: public RSAPublicBCPGKey(BCPGInputStream in) throws IOException {
20: this .n = new MPInteger(in);
21: this .e = new MPInteger(in);
22: }
23:
24: /**
25: *
26: * @param n the modulus
27: * @param e the public exponent
28: */
29: public RSAPublicBCPGKey(BigInteger n, BigInteger e) {
30: this .n = new MPInteger(n);
31: this .e = new MPInteger(e);
32: }
33:
34: public BigInteger getPublicExponent() {
35: return e.getValue();
36: }
37:
38: public BigInteger getModulus() {
39: return n.getValue();
40: }
41:
42: /**
43: * return "PGP"
44: *
45: * @see org.bouncycastle.bcpg.BCPGKey#getFormat()
46: */
47: public String getFormat() {
48: return "PGP";
49: }
50:
51: /**
52: * return the standard PGP encoding of the key.
53: *
54: * @see org.bouncycastle.bcpg.BCPGKey#getEncoded()
55: */
56: public byte[] getEncoded() {
57: try {
58: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
59: BCPGOutputStream pgpOut = new BCPGOutputStream(bOut);
60:
61: pgpOut.writeObject(this );
62:
63: return bOut.toByteArray();
64: } catch (IOException e) {
65: return null;
66: }
67: }
68:
69: public void encode(BCPGOutputStream out) throws IOException {
70: out.writeObject(n);
71: out.writeObject(e);
72: }
73: }
|