summaryrefslogtreecommitdiff
path: root/java/security/KeyPairGenerator.java
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2015-02-02 15:28:40 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2015-02-02 15:28:40 +0000
commit55c5097f9ce57cb5ebdbec6383c6c89ad4933348 (patch)
treee70deaabb74a1793da3f94d6d3c51feccd85cc0e /java/security/KeyPairGenerator.java
parent92f6e5177fbd0c8bfdbecce4b5704d981f4988bb (diff)
downloadclasspath-55c5097f9ce57cb5ebdbec6383c6c89ad4933348.tar.gz
PR64881: KeyPairGenerator.genKeyPair() ends up calling the default generateKeyPair method which returns a DSA generator
2015-01-30 Andrew John Hughes <gnu_andrew@member.fsf.org> PR classpath/64881 * NEWS: Updated. * java/security/KeyPairGenerator.java: (genKeyPair()): Document properly. Call original method, generateKeyPair(). (generateKeyPair()): Document properly. Use provider and algorithm values if set rather than just defaulting to GNU and DSA. Signed-off-by: Andrew John Hughes <gnu_andrew@member.fsf.org>
Diffstat (limited to 'java/security/KeyPairGenerator.java')
-rw-r--r--java/security/KeyPairGenerator.java65
1 files changed, 47 insertions, 18 deletions
diff --git a/java/security/KeyPairGenerator.java b/java/security/KeyPairGenerator.java
index 19724da6f..457c5a531 100644
--- a/java/security/KeyPairGenerator.java
+++ b/java/security/KeyPairGenerator.java
@@ -1,5 +1,5 @@
/* KeyPairGenerator.java --- Key Pair Generator Class
- Copyright (C) 1999, 2002, 2003, 2004, 2005, 2014 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2002, 2003, 2004, 2005, 2014, 2015 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -278,9 +278,17 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
}
/**
- * Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
- *
- * <p>This method generates a unique key-pair each time it is called.</p>
+ * <p>
+ * Generates a new key pair. If a provider hasn't been selected,
+ * it defaults to generating a "DSA" {@link KeyPair} using the "GNU"
+ * security provider. If the provider hasn't been initialised, then
+ * the provider-specified default key size and other parameters are
+ * used.
+ * </p>
+ * <p>
+ * A new key pair is generated on each call to this method. It
+ * is functionally equivalent to {@link #genKeyPair()}.
+ * </p>
*
* @return a new unique {@link KeyPair}.
* @see #generateKeyPair()
@@ -288,28 +296,49 @@ public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
*/
public final KeyPair genKeyPair()
{
- try
- {
- return getInstance("DSA", "GNU").generateKeyPair();
- }
- catch (Exception e)
- {
- System.err.println("genKeyPair failed: " + e);
- e.printStackTrace();
- return null;
- }
+ return generateKeyPair();
}
/**
- * Generates a new "DSA" {@link KeyPair} from the "GNU" security provider.
- *
- * <p>This method generates a unique key pair each time it is called.</p>
+ * <p>
+ * Generates a new key pair. If a provider hasn't been selected,
+ * it defaults to generating a "DSA" {@link KeyPair} using the "GNU"
+ * security provider. If the provider hasn't been initialised, then
+ * the provider-specified default key size and other parameters are
+ * used.
+ * </p>
+ * <p>
+ * A new key pair is generated on each call to this method. It
+ * is functionally equivalent to {@link #generateKeyPair()}.
+ * </p>
*
* @return a new unique {@link KeyPair}.
* @see #genKeyPair()
*/
public KeyPair generateKeyPair()
{
- return genKeyPair();
+ try
+ {
+ Provider providerToUse = null;
+ String algToUse = null;
+
+ if (provider == null)
+ providerToUse = Security.getProvider("GNU");
+ else
+ providerToUse = provider;
+
+ if (algorithm == null)
+ algToUse = "DSA";
+ else
+ algToUse = algorithm;
+
+ return getInstance(algToUse, providerToUse).generateKeyPair();
+ }
+ catch (Exception e)
+ {
+ System.err.println("genKeyPair failed: " + e);
+ e.printStackTrace();
+ return null;
+ }
}
}