01: package org.bouncycastle.bcpg;
02:
03: import java.io.*;
04: import java.math.BigInteger;
05:
06: /**
07: * base class for an ElGamal Secret Key.
08: */
09: public class ElGamalSecretBCPGKey extends BCPGObject implements BCPGKey {
10: MPInteger x;
11:
12: /**
13: *
14: * @param in
15: * @throws IOException
16: */
17: public ElGamalSecretBCPGKey(BCPGInputStream in) throws IOException {
18: this .x = new MPInteger(in);
19: }
20:
21: /**
22: *
23: * @param x
24: */
25: public ElGamalSecretBCPGKey(BigInteger x) {
26: this .x = new MPInteger(x);
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: public BigInteger getX() {
39: return x.getValue();
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(x);
62: }
63: }
|