01: package org.bouncycastle.jce.provider;
02:
03: import java.security.InvalidKeyException;
04: import java.security.PrivateKey;
05: import java.security.PublicKey;
06:
07: import org.bouncycastle.crypto.params.AsymmetricKeyParameter;
08: import org.bouncycastle.crypto.params.GOST3410Parameters;
09: import org.bouncycastle.crypto.params.GOST3410PrivateKeyParameters;
10: import org.bouncycastle.crypto.params.GOST3410PublicKeyParameters;
11: import org.bouncycastle.jce.interfaces.GOST3410PrivateKey;
12: import org.bouncycastle.jce.interfaces.GOST3410PublicKey;
13: import org.bouncycastle.jce.spec.GOST3410PublicKeyParameterSetSpec;
14:
15: /**
16: * utility class for converting jce/jca GOST3410-94 objects
17: * objects into their org.bouncycastle.crypto counterparts.
18: */
19: public class GOST3410Util {
20: static public AsymmetricKeyParameter generatePublicKeyParameter(
21: PublicKey key) throws InvalidKeyException {
22: if (key instanceof GOST3410PublicKey) {
23: GOST3410PublicKey k = (GOST3410PublicKey) key;
24: GOST3410PublicKeyParameterSetSpec p = k.getParameters()
25: .getPublicKeyParameters();
26:
27: return new GOST3410PublicKeyParameters(
28: k.getY(),
29: new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
30: }
31:
32: throw new InvalidKeyException(
33: "can't identify GOST3410 public key: "
34: + key.getClass().getName());
35: }
36:
37: static public AsymmetricKeyParameter generatePrivateKeyParameter(
38: PrivateKey key) throws InvalidKeyException {
39: if (key instanceof GOST3410PrivateKey) {
40: GOST3410PrivateKey k = (GOST3410PrivateKey) key;
41: GOST3410PublicKeyParameterSetSpec p = k.getParameters()
42: .getPublicKeyParameters();
43:
44: return new GOST3410PrivateKeyParameters(
45: k.getX(),
46: new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
47: }
48:
49: throw new InvalidKeyException(
50: "can't identify GOST3410 private key.");
51: }
52: }
|