summaryrefslogtreecommitdiffstats
path: root/pki
diff options
context:
space:
mode:
authorcfu <cfu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2010-11-03 19:53:31 +0000
committercfu <cfu@c9f7a03b-bd48-0410-a16d-cbbf54688b0b>2010-11-03 19:53:31 +0000
commitd6e1b30eb8b2c88ce7c895e5afb3c3ff04ac6034 (patch)
tree3774cf9302d1d9e366695eed733d47955ad1dac3 /pki
parentdf67f8c9c40877aa6190f26649fde020eb0429bb (diff)
downloadpki-d6e1b30eb8b2c88ce7c895e5afb3c3ff04ac6034.tar.gz
pki-d6e1b30eb8b2c88ce7c895e5afb3c3ff04ac6034.tar.xz
pki-d6e1b30eb8b2c88ce7c895e5afb3c3ff04ac6034.zip
Bug 645874 - rfe ecc - add ecc curve name support in JSS and CS interface
git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@1467 c9f7a03b-bd48-0410-a16d-cbbf54688b0b
Diffstat (limited to 'pki')
-rw-r--r--pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java59
1 files changed, 59 insertions, 0 deletions
diff --git a/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
index 15aac27b7..1b2a2bdf1 100644
--- a/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
+++ b/pki/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java
@@ -166,6 +166,65 @@ public class CryptoUtil {
g.setKeyPairUsages(usage_ops, usage_mask);
g.initialize(keysize);
+
+ KeyPair pair = g.genKeyPair();
+
+ return pair;
+ }
+
+ /**
+ * Generates an ecc key pair by curve name
+ */
+ public static KeyPair generateECCKeyPair(String token, String curveName)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+ return generateECCKeyPair(token, curveName, null, null);
+ }
+
+ public static KeyPair generateECCKeyPair(CryptoToken token, String curveName)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+ return generateECCKeyPair(token, curveName, null, null);
+ }
+
+ public static KeyPair generateECCKeyPair(String token, String curveName,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+ CryptoToken t = getTokenByName(token);
+ return generateECCKeyPair(t, curveName, usage_ops, usage_mask);
+ }
+
+ public static KeyPair generateECCKeyPair(CryptoToken token, String curveName,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_ops,
+ org.mozilla.jss.crypto.KeyPairGeneratorSpi.Usage[] usage_mask)
+ throws CryptoManager.NotInitializedException,
+ NoSuchTokenException,
+ NoSuchAlgorithmException,
+ TokenException {
+ KeyPairAlgorithm alg = KeyPairAlgorithm.EC;
+ KeyPairGenerator g = token.getKeyPairGenerator(alg);
+
+ g.setKeyPairUsages(usage_ops, usage_mask);
+
+ System.out.println("CryptoUtil: generateECCKeyPair: curve = "+ curveName);
+ int curveCode = 0;
+ try {
+ curveCode = g.getCurveCodeByName(curveName);
+ } catch (Exception e) {
+ System.out.println("CryptoUtil: generateECCKeyPair: "+ e.toString());
+ throw new NoSuchAlgorithmException();
+ }
+ g.initialize(curveCode);
+
+ System.out.println("CryptoUtil: generateECCKeyPair: after KeyPairGenerator initialize with:"+ curveName);
KeyPair pair = g.genKeyPair();
return pair;