diff options
Diffstat (limited to 'pki/base/util/src/netscape/security/provider/DSAPrivateKey.java')
-rw-r--r-- | pki/base/util/src/netscape/security/provider/DSAPrivateKey.java | 115 |
1 files changed, 58 insertions, 57 deletions
diff --git a/pki/base/util/src/netscape/security/provider/DSAPrivateKey.java b/pki/base/util/src/netscape/security/provider/DSAPrivateKey.java index fbbb29c2f..f480ea08e 100644 --- a/pki/base/util/src/netscape/security/provider/DSAPrivateKey.java +++ b/pki/base/util/src/netscape/security/provider/DSAPrivateKey.java @@ -33,18 +33,18 @@ import netscape.security.x509.AlgIdDSA; /** * A PKCS#8 private key for the Digital Signature Algorithm. - * + * * @author Benjamin Renaud - * + * * @version 1.47, 97/12/10 - * + * * @see DSAPublicKey * @see AlgIdDSA * @see DSA */ -public final class DSAPrivateKey extends PKCS8Key implements - java.security.interfaces.DSAPrivateKey, Serializable { +public final class DSAPrivateKey extends PKCS8Key +implements java.security.interfaces.DSAPrivateKey, Serializable { /** use serialVersionUID from JDK 1.1. for interoperability */ private static final long serialVersionUID = -3244453684193605938L; @@ -61,27 +61,28 @@ public final class DSAPrivateKey extends PKCS8Key implements /** * Make a DSA private key out of a private key and three parameters. */ - public DSAPrivateKey(BigInteger x, BigInteger p, BigInteger q, BigInteger g) - throws InvalidKeyException { - this.x = x; - algid = new AlgIdDSA(p, q, g); - - try { - key = new DerValue(DerValue.tag_Integer, x.toByteArray()) - .toByteArray(); - encode(); - } catch (IOException e) { - throw new InvalidKeyException("could not DER encode x: " - + e.getMessage()); - } + public DSAPrivateKey(BigInteger x, BigInteger p, + BigInteger q, BigInteger g) + throws InvalidKeyException { + this.x = x; + algid = new AlgIdDSA(p, q, g); + + try { + key = new DerValue(DerValue.tag_Integer, + x.toByteArray()).toByteArray(); + encode(); + } catch (IOException e) { + throw new InvalidKeyException("could not DER encode x: " + + e.getMessage()); + } } /** * Make a DSA private key from its DER encoding (PKCS #8). */ public DSAPrivateKey(byte[] encoded) throws InvalidKeyException { - clearOldKey(); - decode(encoded); + clearOldKey(); + decode(encoded); } /** @@ -89,58 +90,58 @@ public final class DSAPrivateKey extends PKCS8Key implements * parameters could not be parsed. */ public DSAParams getParams() { - try { - if (algid instanceof DSAParams) { - return (DSAParams) algid; - } else { - DSAParameterSpec paramSpec; - AlgorithmParameters algParams = algid.getParameters(); - if (algParams == null) { - return null; - } - paramSpec = (DSAParameterSpec) algParams - .getParameterSpec(DSAParameterSpec.class); - return (DSAParams) paramSpec; - } - } catch (InvalidParameterSpecException e) { - return null; - } + try { + if (algid instanceof DSAParams) { + return (DSAParams)algid; + } else { + DSAParameterSpec paramSpec; + AlgorithmParameters algParams = algid.getParameters(); + if (algParams == null) { + return null; + } + paramSpec = (DSAParameterSpec)algParams.getParameterSpec + (DSAParameterSpec.class); + return (DSAParams)paramSpec; + } + } catch (InvalidParameterSpecException e) { + return null; + } } /** * Get the raw private key, x, without the parameters. - * + * */ public BigInteger getX() { - return x; + return x; } private void clearOldKey() { - int i; - if (this.encodedKey != null) { - for (i = 0; i < this.encodedKey.length; i++) { - this.encodedKey[i] = (byte) 0x00; - } - } - if (this.key != null) { - for (i = 0; i < this.key.length; i++) { - this.key[i] = (byte) 0x00; - } - } + int i; + if (this.encodedKey != null) { + for (i = 0; i < this.encodedKey.length; i++) { + this.encodedKey[i] = (byte)0x00; + } + } + if (this.key != null) { + for (i = 0; i < this.key.length; i++) { + this.key[i] = (byte)0x00; + } + } } public String toString() { - return "Sun DSA Private Key \nparameters:" + algid + "\nx: " - + x.toString(16) + "\n"; + return "Sun DSA Private Key \nparameters:" + algid + "\nx: " + + x.toString(16) + "\n"; } protected void parseKeyBits() throws InvalidKeyException { - DerInputStream in = new DerInputStream(key); + DerInputStream in = new DerInputStream(key); - try { - x = in.getInteger().toBigInteger(); - } catch (IOException e) { - throw new InvalidKeyException(e.getMessage()); - } + try { + x = in.getInteger().toBigInteger(); + } catch (IOException e) { + throw new InvalidKeyException(e.getMessage()); + } } } |