summaryrefslogtreecommitdiff
path: root/gnu/java/security/jce/sig/EncodedKeyFactory.java
diff options
context:
space:
mode:
authorRaif S. Naffah <raif@swiftdsl.com.au>2006-02-26 04:10:38 +0000
committerRaif S. Naffah <raif@swiftdsl.com.au>2006-02-26 04:10:38 +0000
commit21e14eddf7837b2578c4a6a8b83278706c3b2f6e (patch)
treef45797b18e0a4ca37f57e6087273617b2a7fb240 /gnu/java/security/jce/sig/EncodedKeyFactory.java
parent511c1460e1aa3976f3a3cbefa39dba71a6379c35 (diff)
downloadclasspath-21e14eddf7837b2578c4a6a8b83278706c3b2f6e.tar.gz
2006-02-26 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/java/security/jce/sig/EncodedKeyFactory.java (log): New field. (engineGeneratePublic): Added logging. (engineGeneratePrivate): Likewise. * gnu/java/security/key/rsa/RSAKeyPairX509Codec.java (log): New field. (encodePublicKey): Added logging. Clarified in method documentation that params is optional, but is always NULL if present. (decodePublicKey): Added logging. Handle optional NULL element.
Diffstat (limited to 'gnu/java/security/jce/sig/EncodedKeyFactory.java')
-rw-r--r--gnu/java/security/jce/sig/EncodedKeyFactory.java150
1 files changed, 90 insertions, 60 deletions
diff --git a/gnu/java/security/jce/sig/EncodedKeyFactory.java b/gnu/java/security/jce/sig/EncodedKeyFactory.java
index 6c1a19abd..60152c279 100644
--- a/gnu/java/security/jce/sig/EncodedKeyFactory.java
+++ b/gnu/java/security/jce/sig/EncodedKeyFactory.java
@@ -62,6 +62,8 @@ import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.RSAPrivateCrtKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.X509EncodedKeySpec;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.crypto.interfaces.DHPrivateKey;
import javax.crypto.interfaces.DHPublicKey;
@@ -75,6 +77,8 @@ import javax.crypto.spec.DHPublicKeySpec;
public class EncodedKeyFactory
extends KeyFactorySpi
{
+ private static final Logger log = Logger.getLogger(EncodedKeyFactory.class.getName());
+
// implicit 0-arguments constructor
// Class methods
@@ -192,79 +196,105 @@ public class EncodedKeyFactory
protected PublicKey engineGeneratePublic(KeySpec keySpec)
throws InvalidKeySpecException
{
- if (keySpec instanceof DSAPublicKeySpec)
- return decodeDSSPublicKey((DSAPublicKeySpec) keySpec);
-
- if (keySpec instanceof RSAPublicKeySpec)
- return decodeRSAPublicKey((RSAPublicKeySpec) keySpec);
-
- if (keySpec instanceof DHPublicKeySpec)
- return decodeDHPublicKey((DHPublicKeySpec) keySpec);
-
- if (! (keySpec instanceof X509EncodedKeySpec))
- throw new InvalidKeySpecException("Unsupported key specification");
-
- byte[] input = ((X509EncodedKeySpec) keySpec).getEncoded();
-
- // try DSS
- try
- {
- return DSSPublicKey.valueOf(input);
- }
- catch (InvalidParameterException ignored)
- {
- }
+ log.entering(this.getClass().getName(), "engineGeneratePublic()", keySpec);
- // try RSA
- try
- {
- return GnuRSAPublicKey.valueOf(input);
- }
- catch (InvalidParameterException ignored)
+ PublicKey result = null;
+ if (keySpec instanceof DSAPublicKeySpec)
+ result = decodeDSSPublicKey((DSAPublicKeySpec) keySpec);
+ else if (keySpec instanceof RSAPublicKeySpec)
+ result = decodeRSAPublicKey((RSAPublicKeySpec) keySpec);
+ else if (keySpec instanceof DHPublicKeySpec)
+ result = decodeDHPublicKey((DHPublicKeySpec) keySpec);
+ else
{
+ if (! (keySpec instanceof X509EncodedKeySpec))
+ throw new InvalidKeySpecException("Unsupported key specification");
+
+ byte[] input = ((X509EncodedKeySpec) keySpec).getEncoded();
+ boolean ok = false;
+ // try DSS
+ try
+ {
+ result = DSSPublicKey.valueOf(input);
+ ok = true;
+ }
+ catch (InvalidParameterException ignored)
+ {
+ log.log(Level.FINE, "Exception in DSSPublicKey.valueOf(). Ignore",
+ ignored);
+ }
+
+ if (! ok) // try RSA
+ try
+ {
+ result = GnuRSAPublicKey.valueOf(input);
+ ok = true;
+ }
+ catch (InvalidParameterException ignored)
+ {
+ log.log(Level.FINE,
+ "Exception in GnuRSAPublicKey.valueOf(). Ignore",
+ ignored);
+ }
+
+ if (! ok) // try DH
+ result = decodeDHPublicKey(input);
}
- // try DH
- return decodeDHPublicKey(input);
+ log.exiting(this.getClass().getName(), "engineGeneratePublic()", result);
+ return result;
}
protected PrivateKey engineGeneratePrivate(KeySpec keySpec)
throws InvalidKeySpecException
{
- if (keySpec instanceof DSAPrivateKeySpec)
- return decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec);
-
- if (keySpec instanceof RSAPrivateCrtKeySpec)
- return decodeRSAPrivateKey((RSAPrivateCrtKeySpec) keySpec);
-
- if (keySpec instanceof DHPrivateKeySpec)
- return decodeDHPrivateKey((DHPrivateKeySpec) keySpec);
-
- if (! (keySpec instanceof PKCS8EncodedKeySpec))
- throw new InvalidKeySpecException("Unsupported key specification");
+ log.entering(this.getClass().getName(), "engineGeneratePrivate()", keySpec);
- byte[] input = ((PKCS8EncodedKeySpec) keySpec).getEncoded();
-
- // try DSS
- try
- {
- return DSSPrivateKey.valueOf(input);
- }
- catch (InvalidParameterException ignored)
- {
- }
-
- // try RSA
- try
- {
- return GnuRSAPrivateKey.valueOf(input);
- }
- catch (InvalidParameterException ignored)
+ PrivateKey result = null;
+ if (keySpec instanceof DSAPrivateKeySpec)
+ result = decodeDSSPrivateKey((DSAPrivateKeySpec) keySpec);
+ else if (keySpec instanceof RSAPrivateCrtKeySpec)
+ result = decodeRSAPrivateKey((RSAPrivateCrtKeySpec) keySpec);
+ else if (keySpec instanceof DHPrivateKeySpec)
+ result = decodeDHPrivateKey((DHPrivateKeySpec) keySpec);
+ else
{
+ if (! (keySpec instanceof PKCS8EncodedKeySpec))
+ throw new InvalidKeySpecException("Unsupported key specification");
+
+ byte[] input = ((PKCS8EncodedKeySpec) keySpec).getEncoded();
+ boolean ok = false;
+ // try DSS
+ try
+ {
+ result = DSSPrivateKey.valueOf(input);
+ ok = true;
+ }
+ catch (InvalidParameterException ignored)
+ {
+ log.log(Level.FINE, "Exception in DSSPrivateKey.valueOf(). Ignore",
+ ignored);
+ }
+
+ if (! ok) // try RSA
+ try
+ {
+ result = GnuRSAPrivateKey.valueOf(input);
+ ok = true;
+ }
+ catch (InvalidParameterException ignored)
+ {
+ log.log(Level.FINE,
+ "Exception in GnuRSAPrivateKey.valueOf(). Ignore",
+ ignored);
+ }
+
+ if (! ok) // try DH
+ result = decodeDHPrivateKey(input);
}
- // try DH
- return decodeDHPrivateKey(input);
+ log.exiting(this.getClass().getName(), "engineGeneratePrivate()", result);
+ return result;
}
protected KeySpec engineGetKeySpec(Key key, Class keySpec)