KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > maverick > crypto > publickey > DsaPrivateKey


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.maverick.crypto.publickey;
21
22 import java.math.BigInteger JavaDoc;
23
24 import com.maverick.crypto.digests.SHA1Digest;
25
26 public class DsaPrivateKey
27     extends DsaKey {
28
29   protected BigInteger JavaDoc x;
30
31   public DsaPrivateKey(BigInteger JavaDoc p, BigInteger JavaDoc q, BigInteger JavaDoc g, BigInteger JavaDoc x) {
32     super(p, q, g);
33     this.x = x;
34   }
35
36   /* (non-Javadoc)
37  * @see com.maverick.crypto.publickey.DsaPrivateKeyInterface#getX()
38  */

39 public BigInteger JavaDoc getX() {
40     return x;
41   }
42
43   /* (non-Javadoc)
44    * @see com.maverick.ssh.SshPrivateKey#sign(byte[])
45    */

46   /* (non-Javadoc)
47  * @see com.maverick.crypto.publickey.DsaPrivateKeyInterface#sign(byte[])
48  */

49 public byte[] sign(byte[] msg) {
50
51     SHA1Digest h = new SHA1Digest();
52     h.update(msg, 0, msg.length);
53     byte[] data = new byte[h.getDigestSize()];
54     h.doFinal(data, 0);
55     return Dsa.sign(x, p, q, g, data);
56   }
57
58   public boolean equals(Object JavaDoc obj) {
59     if (obj instanceof DsaPrivateKey) {
60       DsaPrivateKey key = (DsaPrivateKey) obj;
61       return x.equals(key.x)
62           && p.equals(key.p)
63           && q.equals(key.q)
64           && g.equals(key.g);
65     }
66     return false;
67   }
68
69 }
70
Popular Tags