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