01: package org.bouncycastle.jce.provider;
02:
03: import java.security.InvalidKeyException;
04: import java.security.PrivateKey;
05: import java.security.PublicKey;
06: import java.security.interfaces.DSAPrivateKey;
07: import java.security.interfaces.DSAPublicKey;
08:
09: import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
10: import org.bouncycastle.crypto.params.DSAParameters;
11: import org.bouncycastle.crypto.params.DSAPrivateKeyParameters;
12: import org.bouncycastle.crypto.params.DSAPublicKeyParameters;
13:
14: /**
15: * utility class for converting jce/jca DSA objects
16: * objects into their org.bouncycastle.crypto counterparts.
17: */
18: public class DSAUtil {
19: static public AsymmetricKeyParameter generatePublicKeyParameter(
20: PublicKey key) throws InvalidKeyException {
21: if (key instanceof DSAPublicKey) {
22: DSAPublicKey k = (DSAPublicKey) key;
23:
24: return new DSAPublicKeyParameters(k.getY(),
25: new DSAParameters(k.getParams().getP(), k
26: .getParams().getQ(), k.getParams().getG()));
27: }
28:
29: throw new InvalidKeyException("can't identify DSA public key: "
30: + key.getClass().getName());
31: }
32:
33: static public AsymmetricKeyParameter generatePrivateKeyParameter(
34: PrivateKey key) throws InvalidKeyException {
35: if (key instanceof DSAPrivateKey) {
36: DSAPrivateKey k = (DSAPrivateKey) key;
37:
38: return new DSAPrivateKeyParameters(k.getX(),
39: new DSAParameters(k.getParams().getP(), k
40: .getParams().getQ(), k.getParams().getG()));
41: }
42:
43: throw new InvalidKeyException("can't identify DSA private key.");
44: }
45: }
|