Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: cryptix/jce/provider/elgamal/ElGamalPrivateKeyCryptix.java


1   /* $Id: ElGamalPrivateKeyCryptix.java,v 1.2 2000/01/20 14:59:28 gelderen Exp $
2    *
3    * Copyright (C) 2000 The Cryptix Foundation Limited.
4    * All rights reserved.
5    *
6    * Use, modification, copying and distribution of this software is subject
7    * the terms and conditions of the Cryptix General Licence. You should have
8    * received a copy of the Cryptix General Licence along with this library;
9    * if not, you can download a copy from http://www.cryptix.org/ .
10   */
11  package cryptix.jce.provider.elgamal;
12  
13  
14  import cryptix.jce.ElGamalParams;
15  import cryptix.jce.ElGamalPrivateKey;
16  import cryptix.jce.util.MPIOutputStream;
17  
18  import java.io.ByteArrayOutputStream;
19  import java.io.IOException;
20  import java.math.BigInteger;
21  
22  
23  /**
24   * @version $Revision: 1.2 $
25   * @author  Jeroen C. van Gelderen (gelderen@cryptix.org)
26   */
27  /*package*/ final class ElGamalPrivateKeyCryptix
28  implements ElGamalPrivateKey
29  {
30  
31  // Instance variables
32  //...........................................................................
33  
34      private final BigInteger x;
35      private final ElGamalParams params;
36      
37  
38  // Constructor
39  //...........................................................................
40  
41      /*package*/ ElGamalPrivateKeyCryptix(BigInteger x, ElGamalParams params)
42      {
43          this.x      = x;
44          this.params = params;
45      }
46      
47  
48  // Implementation of ElGamalPrivateKey interface
49  //...........................................................................
50  
51      public BigInteger getX()
52      {
53          return this.x;
54      }
55      
56  
57  // Implementation of ElGamalKey interface
58  //...........................................................................
59  
60      public ElGamalParams getParams()
61      {
62          return this.params;
63      }
64      
65  
66  // Implementation of Key interface
67  //...........................................................................
68  
69      public String getAlgorithm()
70      {
71          return "ElGamal";
72      }
73      
74      
75      public String getFormat()
76      {
77          return "Cryptix";
78      }
79      
80      
81      public byte[] getEncoded()
82      {
83          try
84          {
85              ByteArrayOutputStream baos = new ByteArrayOutputStream();
86              MPIOutputStream       mos  = new MPIOutputStream(baos);
87              mos.write(this.params.getP());
88              mos.write(this.params.getQ());
89              mos.write(this.params.getG());
90              mos.write(this.x);
91              mos.flush();
92              mos.close();
93              return baos.toByteArray();
94          }
95          catch(IOException e)
96          {
97              throw new RuntimeException("PANIC");
98          }
99      }
100 }