summaryrefslogtreecommitdiff
path: root/gnu/java/security/key
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-02-23 12:54:46 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-02-23 12:54:46 +0000
commiteb292aaa795e28e325d1e439e88f2ad526cb4e7e (patch)
treeede11b56bbd8dd1d6d51a8efd5daed2ea4a69488 /gnu/java/security/key
parent15fe13942e812b00a55e12bceb3e4a03322501fe (diff)
downloadclasspath-eb292aaa795e28e325d1e439e88f2ad526cb4e7e.tar.gz
2006-02-23 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/javax/crypto/key/dh/GnuDHKeyPairGenerator.java (DEFAULT_PRIME_SIZE): Made public. (DEFAULT_EXPONENT_SIZE): Likewise. (setup): Handle DHParameterSpec as well. * gnu/javax/crypto/key/dh/GnuDHKey.java (getEncoded): Return defaultFormat instead of Raw. * gnu/javax/crypto/key/dh/DHKeyPairX509Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePublicKey): Use DerUtil. * gnu/javax/crypto/key/dh/DHKeyPairPKCS8Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePrivateKey): Use DerUtil. * gnu/javax/crypto/jce/GnuCrypto.java (run): Updated mapping of KeyAgreement.DH. Added mappings for AlgorithmParameters.DH and AlgorithmParameterGenerator.DH. * gnu/javax/crypto/jce/DiffieHellmanImpl.java: New file. * gnu/javax/crypto/jce/sig/DHParametersGenerator.java: Likewise. * gnu/javax/crypto/jce/sig/DHParameters.java: Likewise. * gnu/javax/crypto/jce/sig/DHKeyFactory.java (engineGeneratePrivate): Return result. (engineGeneratePublic): Likewise. * gnu/java/security/util/DerUtil.java: New file. * gnu/java/security/sig/rsa/RSASignatureFactory.java (getNames): Include only valid RSA PKCS1 (v1.5) signature names. * gnu/java/security/sig/rsa/RSAPKCS1V1_5SignatureX509Codec.java (RSAPKCS1V1_5SignatureX509Codec): Removed. (checkIsConstructed): Likewise. * gnu/java/security/sig/dss/DSSSignatureX509Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodeSignature): Use DerUtil. * gnu/java/security/key/rsa/RSAKeyPairX509Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePublicKey): Use DerUtil. * gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePrivateKey): Use DerUtil. * gnu/java/security/key/dss/DSSKeyPairX509Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePublicKey): Use DerUtil. * gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java (checkIsConstructed): Removed. (checkIsBigInteger): Likewise. (decodePrivateKey): Use DerUtil. * gnu/java/security/key/dss/DSSKeyPairGenerator.java (DEFAULT_MODULUS_LENGTH): Made it public. * gnu/java/security/key/dss/DSSKey.java (getEncoded): Return defaultFormat instead of Raw. * gnu/java/security/jce/sig/DSSParametersGenerator.java: New file. * gnu/java/security/jce/sig/DSSParameters.java: Likewise.. * gnu/java/security/jce/sig/DSSKeyFactory.java (engineGeneratePrivate): Return result. (engineGeneratePublic): Likewise. * gnu/javax/crypto/DiffieHellmanImpl: Removed.
Diffstat (limited to 'gnu/java/security/key')
-rw-r--r--gnu/java/security/key/dss/DSSKey.java5
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairGenerator.java2
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java25
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairX509Codec.java27
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java39
-rw-r--r--gnu/java/security/key/rsa/RSAKeyPairX509Codec.java23
6 files changed, 38 insertions, 83 deletions
diff --git a/gnu/java/security/key/dss/DSSKey.java b/gnu/java/security/key/dss/DSSKey.java
index 8c906a650..428cab1e7 100644
--- a/gnu/java/security/key/dss/DSSKey.java
+++ b/gnu/java/security/key/dss/DSSKey.java
@@ -39,7 +39,6 @@ exception statement from your version. */
package gnu.java.security.key.dss;
import gnu.java.security.Registry;
-import gnu.java.security.key.IKeyPairCodec;
import gnu.java.security.util.FormatUtil;
import java.math.BigInteger;
@@ -60,7 +59,7 @@ import java.security.spec.DSAParameterSpec;
* the relevant <code>getEncoded()</code> methods of each of the private and
* public keys.</p>
*
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
* @see DSSPrivateKey#getEncoded
* @see DSSPublicKey#getEncoded
*/
@@ -142,7 +141,7 @@ public abstract class DSSKey implements Key, DSAKey
/** @deprecated see getEncoded(int). */
public byte[] getEncoded()
{
- return getEncoded(IKeyPairCodec.RAW_FORMAT);
+ return getEncoded(defaultFormat);
}
public String getFormat()
diff --git a/gnu/java/security/key/dss/DSSKeyPairGenerator.java b/gnu/java/security/key/dss/DSSKeyPairGenerator.java
index 23dd12796..5aa746147 100644
--- a/gnu/java/security/key/dss/DSSKeyPairGenerator.java
+++ b/gnu/java/security/key/dss/DSSKeyPairGenerator.java
@@ -159,7 +159,7 @@ public class DSSKeyPairGenerator implements IKeyPairGenerator
public static final String PREFERRED_ENCODING_FORMAT = "gnu.crypto.dss.encoding";
/** Default value for the modulus length. */
- private static final int DEFAULT_MODULUS_LENGTH = 1024;
+ public static final int DEFAULT_MODULUS_LENGTH = 1024;
/** Default encoding format to use when none was specified. */
private static final int DEFAULT_ENCODING_FORMAT = Registry.RAW_ENCODING_ID;
diff --git a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
index 671b5d66d..30e30bd14 100644
--- a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
@@ -45,6 +45,7 @@ import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
import gnu.java.security.der.DERWriter;
import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
import gnu.java.security.util.Util;
import java.io.ByteArrayOutputStream;
@@ -68,18 +69,6 @@ public class DSSKeyPairPKCS8Codec
// implicit 0-arguments constructor
- private static void checkIsConstructed(DERValue v, String msg)
- {
- if (! v.isConstructed())
- throw new InvalidParameterException(msg);
- }
-
- private static void checkIsBigInteger(DERValue v, String msg)
- {
- if (! (v.getValue() instanceof BigInteger))
- throw new InvalidParameterException(msg);
- }
-
public int getFormatID()
{
return PKCS8_FORMAT;
@@ -199,7 +188,7 @@ public class DSSKeyPairPKCS8Codec
try
{
DERValue derPKI = der.read();
- checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
+ DerUtil.checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
DERValue derVersion = der.read();
if (! (derVersion.getValue() instanceof BigInteger))
@@ -210,7 +199,7 @@ public class DSSKeyPairPKCS8Codec
throw new InvalidParameterException("Unexpected Version: " + version);
DERValue derAlgoritmID = der.read();
- checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
+ DerUtil.checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
DERValue derOID = der.read();
OID algOID = (OID) derOID.getValue();
@@ -218,16 +207,16 @@ public class DSSKeyPairPKCS8Codec
throw new InvalidParameterException("Unexpected OID: " + algOID);
DERValue derParams = der.read();
- checkIsConstructed(derParams, "Wrong DSS Parameters field");
+ DerUtil.checkIsConstructed(derParams, "Wrong DSS Parameters field");
DERValue val = der.read();
- checkIsBigInteger(val, "Wrong P field");
+ DerUtil.checkIsBigInteger(val, "Wrong P field");
p = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong Q field");
+ DerUtil.checkIsBigInteger(val, "Wrong Q field");
q = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong G field");
+ DerUtil.checkIsBigInteger(val, "Wrong G field");
g = (BigInteger) val.getValue();
val = der.read();
diff --git a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
index baf58a026..516ef92af 100644
--- a/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairX509Codec.java
@@ -46,6 +46,7 @@ import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
import gnu.java.security.der.DERWriter;
import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -66,18 +67,6 @@ public class DSSKeyPairX509Codec
// implicit 0-arguments constructor
- private static void checkIsConstructed(DERValue v, String msg)
- {
- if (! v.isConstructed())
- throw new InvalidParameterException(msg);
- }
-
- private static void checkIsBigInteger(DERValue v, String msg)
- {
- if (! (v.getValue() instanceof BigInteger))
- throw new InvalidParameterException(msg);
- }
-
public int getFormatID()
{
return X509_FORMAT;
@@ -202,10 +191,10 @@ public class DSSKeyPairX509Codec
try
{
DERValue derSPKI = der.read();
- checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
+ DerUtil.checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
DERValue derAlgorithmID = der.read();
- checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
DERValue derOID = der.read();
if (! (derOID.getValue() instanceof OID))
@@ -216,16 +205,16 @@ public class DSSKeyPairX509Codec
throw new InvalidParameterException("Unexpected OID: " + algOID);
DERValue derParams = der.read();
- checkIsConstructed(derParams, "Wrong DSS Parameters field");
+ DerUtil.checkIsConstructed(derParams, "Wrong DSS Parameters field");
DERValue val = der.read();
- checkIsBigInteger(val, "Wrong P field");
+ DerUtil.checkIsBigInteger(val, "Wrong P field");
p = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong Q field");
+ DerUtil.checkIsBigInteger(val, "Wrong Q field");
q = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong G field");
+ DerUtil.checkIsBigInteger(val, "Wrong G field");
g = (BigInteger) val.getValue();
val = der.read();
@@ -236,7 +225,7 @@ public class DSSKeyPairX509Codec
DERReader dsaPub = new DERReader(yBytes);
val = dsaPub.read();
- checkIsBigInteger(val, "Wrong Y field");
+ DerUtil.checkIsBigInteger(val, "Wrong Y field");
y = (BigInteger) val.getValue();
}
catch (IOException x)
diff --git a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
index 40a67625d..a7f65b610 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java
@@ -53,6 +53,7 @@ import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
import gnu.java.security.der.DERWriter;
import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
/**
* An implementation of an {@link IKeyPairCodec} that knows how to encode /
@@ -65,18 +66,6 @@ public class RSAKeyPairPKCS8Codec
// implicit 0-arguments constructor
- private static void checkIsConstructed(DERValue v, String msg)
- {
- if (! v.isConstructed())
- throw new InvalidParameterException(msg);
- }
-
- private static void checkIsBigInteger(DERValue v, String msg)
- {
- if (! (v.getValue() instanceof BigInteger))
- throw new InvalidParameterException(msg);
- }
-
public int getFormatID()
{
return PKCS8_FORMAT;
@@ -227,16 +216,16 @@ public class RSAKeyPairPKCS8Codec
try
{
DERValue derPKI = der.read();
- checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
+ DerUtil.checkIsConstructed(derPKI, "Wrong PrivateKeyInfo field");
DERValue derVersion = der.read();
- checkIsBigInteger(derVersion, "Wrong Version field");
+ DerUtil.checkIsBigInteger(derVersion, "Wrong Version field");
version = (BigInteger) derVersion.getValue();
if (version.compareTo(BigInteger.ZERO) != 0)
throw new InvalidParameterException("Unexpected Version: " + version);
DERValue derAlgoritmID = der.read();
- checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
+ DerUtil.checkIsConstructed(derAlgoritmID, "Wrong AlgorithmIdentifier field");
DERValue derOID = der.read();
OID algOID = (OID) derOID.getValue();
@@ -248,38 +237,38 @@ public class RSAKeyPairPKCS8Codec
der = new DERReader(pkBytes);
DERValue derRSAPrivateKey = der.read();
- checkIsConstructed(derRSAPrivateKey, "Wrong RSAPrivateKey field");
+ DerUtil.checkIsConstructed(derRSAPrivateKey, "Wrong RSAPrivateKey field");
val = der.read();
- checkIsBigInteger(val, "Wrong RSAPrivateKey Version field");
+ DerUtil.checkIsBigInteger(val, "Wrong RSAPrivateKey Version field");
version = (BigInteger) val.getValue();
if (version.compareTo(BigInteger.ZERO) != 0)
throw new InvalidParameterException("Unexpected RSAPrivateKey Version: "
+ version);
val = der.read();
- checkIsBigInteger(val, "Wrong modulus field");
+ DerUtil.checkIsBigInteger(val, "Wrong modulus field");
n = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong publicExponent field");
+ DerUtil.checkIsBigInteger(val, "Wrong publicExponent field");
e = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong privateExponent field");
+ DerUtil.checkIsBigInteger(val, "Wrong privateExponent field");
d = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong prime1 field");
+ DerUtil.checkIsBigInteger(val, "Wrong prime1 field");
p = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong prime2 field");
+ DerUtil.checkIsBigInteger(val, "Wrong prime2 field");
q = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong exponent1 field");
+ DerUtil.checkIsBigInteger(val, "Wrong exponent1 field");
dP = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong exponent2 field");
+ DerUtil.checkIsBigInteger(val, "Wrong exponent2 field");
dQ = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong coefficient field");
+ DerUtil.checkIsBigInteger(val, "Wrong coefficient field");
qInv = (BigInteger) val.getValue();
}
catch (IOException x)
diff --git a/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
index 5845e7c95..f0a454992 100644
--- a/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
+++ b/gnu/java/security/key/rsa/RSAKeyPairX509Codec.java
@@ -46,6 +46,7 @@ import gnu.java.security.der.DERReader;
import gnu.java.security.der.DERValue;
import gnu.java.security.der.DERWriter;
import gnu.java.security.key.IKeyPairCodec;
+import gnu.java.security.util.DerUtil;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -66,18 +67,6 @@ public class RSAKeyPairX509Codec
// implicit 0-arguments constructor
- private static void checkIsConstructed(DERValue v, String msg)
- {
- if (! v.isConstructed())
- throw new InvalidParameterException(msg);
- }
-
- private static void checkIsBigInteger(DERValue v, String msg)
- {
- if (! (v.getValue() instanceof BigInteger))
- throw new InvalidParameterException(msg);
- }
-
public int getFormatID()
{
return X509_FORMAT;
@@ -193,10 +182,10 @@ public class RSAKeyPairX509Codec
try
{
DERValue derSPKI = der.read();
- checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
+ DerUtil.checkIsConstructed(derSPKI, "Wrong SubjectPublicKeyInfo field");
DERValue derAlgorithmID = der.read();
- checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong AlgorithmIdentifier field");
DERValue derOID = der.read();
if (! (derOID.getValue() instanceof OID))
@@ -214,13 +203,13 @@ public class RSAKeyPairX509Codec
der = new DERReader(spkBytes);
val = der.read();
- checkIsConstructed(derAlgorithmID, "Wrong subjectPublicKey field");
+ DerUtil.checkIsConstructed(derAlgorithmID, "Wrong subjectPublicKey field");
val = der.read();
- checkIsBigInteger(val, "Wrong modulus field");
+ DerUtil.checkIsBigInteger(val, "Wrong modulus field");
n = (BigInteger) val.getValue();
val = der.read();
- checkIsBigInteger(val, "Wrong publicExponent field");
+ DerUtil.checkIsBigInteger(val, "Wrong publicExponent field");
e = (BigInteger) val.getValue();
}
catch (IOException x)