01: package org.bouncycastle.bcpg;
02:
03: import java.io.*;
04: import java.math.BigInteger;
05:
06: /**
07: * base class for a DSA Secret Key.
08: */
09: public class DSASecretBCPGKey extends BCPGObject implements BCPGKey {
10: MPInteger x;
11:
12: /**
13: *
14: * @param in
15: * @throws IOException
16: */
17: public DSASecretBCPGKey(BCPGInputStream in) throws IOException {
18: this .x = new MPInteger(in);
19: }
20:
21: /**
22: *
23: * @param x
24: */
25: public DSASecretBCPGKey(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: /**
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 void encode(BCPGOutputStream out) throws IOException {
57: out.writeObject(x);
58: }
59:
60: /**
61: * @return x
62: */
63: public BigInteger getX() {
64: return x.getValue();
65: }
66: }
|