01: package org.bouncycastle.bcpg;
02:
03: import java.io.*;
04: import java.math.BigInteger;
05:
06: /**
07: * base class for a DSA Public Key.
08: */
09: public class DSAPublicBCPGKey extends BCPGObject implements BCPGKey {
10: MPInteger p;
11: MPInteger q;
12: MPInteger g;
13: MPInteger y;
14:
15: /**
16: * @param in the stream to read the packet from.
17: */
18: public DSAPublicBCPGKey(BCPGInputStream in) throws IOException {
19: this .p = new MPInteger(in);
20: this .q = new MPInteger(in);
21: this .g = new MPInteger(in);
22: this .y = new MPInteger(in);
23: }
24:
25: public DSAPublicBCPGKey(BigInteger p, BigInteger q, BigInteger g,
26: BigInteger y) {
27: this .p = new MPInteger(p);
28: this .q = new MPInteger(q);
29: this .g = new MPInteger(g);
30: this .y = new MPInteger(y);
31: }
32:
33: /**
34: * return "PGP"
35: *
36: * @see org.bouncycastle.bcpg.BCPGKey#getFormat()
37: */
38: public String getFormat() {
39: return "PGP";
40: }
41:
42: /**
43: * return the standard PGP encoding of the key.
44: *
45: * @see org.bouncycastle.bcpg.BCPGKey#getEncoded()
46: */
47: public byte[] getEncoded() {
48: try {
49: ByteArrayOutputStream bOut = new ByteArrayOutputStream();
50: BCPGOutputStream pgpOut = new BCPGOutputStream(bOut);
51:
52: pgpOut.writeObject(this );
53:
54: return bOut.toByteArray();
55: } catch (IOException e) {
56: return null;
57: }
58: }
59:
60: public void encode(BCPGOutputStream out) throws IOException {
61: out.writeObject(p);
62: out.writeObject(q);
63: out.writeObject(g);
64: out.writeObject(y);
65: }
66:
67: /**
68: * @return g
69: */
70: public BigInteger getG() {
71: return g.getValue();
72: }
73:
74: /**
75: * @return p
76: */
77: public BigInteger getP() {
78: return p.getValue();
79: }
80:
81: /**
82: * @return q
83: */
84: public BigInteger getQ() {
85: return q.getValue();
86: }
87:
88: /**
89: * @return g
90: */
91: public BigInteger getY() {
92: return y.getValue();
93: }
94:
95: }
|