summaryrefslogtreecommitdiff
path: root/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-03-25 11:19:17 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-03-25 11:19:17 +0000
commit4c6546e77c9f75fd2deda3883d8cb86dcf0dfd43 (patch)
tree1dd4227079f351746a87ba14975a17150a921fac /gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
parentab9dc3bbbe7479e7129a75f6523afbafe316dc51 (diff)
downloadclasspath-4c6546e77c9f75fd2deda3883d8cb86dcf0dfd43.tar.gz
2006-03-25 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/java/security/pkcs/SignerInfo.java (log): New field. (DEBUG): Removed. (debug): Likewise. (SignerInfo(BERReader)): Updated javadoc. Use JDK logging. (SignerInfo(X500Principal,BigInteger,OID,byte[],OID,byte[],byte[])): New constructor. (encode): New method. * gnu/java/security/pkcs/PKCS7SignedData.java (log): New field. (PKCS7_DATA): Removed. (DEBUG): Likewise. (debug): Likewise. (PKCS7SignedData(BERReader)): Updated javadoc. Use JDK logging. (PKCS7SignedData(Set,PKCS7Data,Certificate[],X509CRL[],Set)): New constructor. (encode): New method. * gnu/java/security/pkcs/PKCS7Data.java: New file. * gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java (log): New field. (encodePrivateKey): Encode x (private MPN) as an OCTET STRING. (decodePrivateKey): Decode x from an OCTET STRING. * gnu/java/security/key/dss/DSSPublicKey.java (str): New field. (toString): New method. * gnu/java/security/key/dss/DSSPrivateKey.java (DEBUG): New field. (str): Likewise. (toString): New method. * gnu/java/security/key/dss/DSSKey.java (str): New Field. (toString): New method. * gnu/java/security/provider/DSAParameterGenerator.java: Removed.
Diffstat (limited to 'gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java')
-rw-r--r--gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
index 30e30bd14..3a115b963 100644
--- a/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
+++ b/gnu/java/security/key/dss/DSSKeyPairPKCS8Codec.java
@@ -55,6 +55,7 @@ import java.security.InvalidParameterException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.ArrayList;
+import java.util.logging.Logger;
/**
* An implementation of an {@link IKeyPairCodec} that knows how to encode /
@@ -65,6 +66,7 @@ import java.util.ArrayList;
public class DSSKeyPairPKCS8Codec
implements IKeyPairCodec
{
+ private static final Logger log = Logger.getLogger(DSSKeyPairPKCS8Codec.class.getName());
private static final OID DSA_ALG_OID = new OID(Registry.DSA_OID_STRING);
// implicit 0-arguments constructor
@@ -137,7 +139,9 @@ public class DSSKeyPairPKCS8Codec
DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
algorithmID);
- DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, Util.trim(x));
+ // The OCTET STRING is the DER encoding of an INTEGER.
+ DERValue derX = new DERValue(DER.INTEGER, x);
+ DERValue derPrivateKey = new DERValue(DER.OCTET_STRING, derX.getEncoded());
ArrayList pki = new ArrayList(3);
pki.add(derVersion);
@@ -180,6 +184,8 @@ public class DSSKeyPairPKCS8Codec
*/
public PrivateKey decodePrivateKey(byte[] input)
{
+ log.entering("DSSKeyPairPKCS8Codec", "decodePrivateKey");
+
if (input == null)
throw new InvalidParameterException("Input bytes MUST NOT be null");
@@ -220,8 +226,13 @@ public class DSSKeyPairPKCS8Codec
g = (BigInteger) val.getValue();
val = der.read();
+ log.finest("val = " + val);
byte[] xBytes = (byte[]) val.getValue();
- x = new BigInteger(1, xBytes);
+ log.finest(Util.dumpString(xBytes, "xBytes: "));
+ DERReader der2 = new DERReader(xBytes);
+ val = der2.read();
+ DerUtil.checkIsBigInteger(val, "Wrong X field");
+ x = (BigInteger) val.getValue();
}
catch (IOException e)
{
@@ -230,6 +241,7 @@ public class DSSKeyPairPKCS8Codec
throw y;
}
+ log.exiting("DSSKeyPairPKCS8Codec", "decodePrivateKey");
return new DSSPrivateKey(Registry.PKCS8_ENCODING_ID, p, q, g, x);
}
}