diff options
author | Abhishek Koneru <akoneru@redhat.com> | 2014-02-26 13:15:57 -0500 |
---|---|---|
committer | Abhishek Koneru <akoneru@redhat.com> | 2014-03-19 19:17:39 -0400 |
commit | 24294c097dd0dd9f7de0202443a8c8e34807bb2f (patch) | |
tree | 03e393bb71fb1263ee85571b26a0f108e1133e1b /base/util | |
parent | fbd1b96a35946b7ebf36afea3f3a2a50dcbf193f (diff) | |
download | pki-24294c097dd0dd9f7de0202443a8c8e34807bb2f.tar.gz pki-24294c097dd0dd9f7de0202443a8c8e34807bb2f.tar.xz pki-24294c097dd0dd9f7de0202443a8c8e34807bb2f.zip |
Changes to KeyClient on the java side.
The KeyClient class on the java side is modified to
have a similar design as the KeyClient class on the python side.
Diffstat (limited to 'base/util')
-rw-r--r-- | base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java index 5e8e323f4..d3eafd7f5 100644 --- a/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java +++ b/base/util/src/com/netscape/cmsutil/crypto/CryptoUtil.java @@ -39,6 +39,7 @@ import java.security.interfaces.RSAPublicKey; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; +import java.util.Random; import java.util.StringTokenizer; import java.util.Vector; @@ -1302,11 +1303,15 @@ public class CryptoUtil { * Generates a symmetric key. */ public static SymmetricKey generateKey(CryptoToken token, - KeyGenAlgorithm alg) + KeyGenAlgorithm alg, int keySize) throws TokenException, NoSuchAlgorithmException, - IllegalStateException { + IllegalStateException, InvalidAlgorithmParameterException { try { KeyGenerator kg = token.getKeyGenerator(alg); + if (alg == KeyGenAlgorithm.AES || alg == KeyGenAlgorithm.RC4 + || alg == KeyGenAlgorithm.RC2) { + kg.initialize(keySize); + } return kg.generate(); } catch (CharConversionException e) { @@ -1533,6 +1538,19 @@ public class CryptoUtil { return certs; } + /** + * Generates a nonve_iv for padding. + * + * @return + */ + public static byte[] getNonceData(int size) { + byte[] iv = new byte[size]; + Random rnd = new Random(); + rnd.nextBytes(iv); + + return iv; + } + public static String unwrapUsingPassphrase(String wrappedRecoveredKey, String recoveryPassphrase) throws IOException, InvalidBERException, InvalidKeyException, IllegalStateException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, NotInitializedException, TokenException, @@ -1605,7 +1623,7 @@ public class CryptoUtil { } public static byte[] createPKIArchiveOptions(CryptoManager manager, CryptoToken token, String transportCert, - SymmetricKey vek, String passphrase, KeyGenAlgorithm keyGenAlg, IVParameterSpec IV) throws TokenException, + SymmetricKey vek, String passphrase, KeyGenAlgorithm keyGenAlg, int symKeySize, IVParameterSpec IV) throws TokenException, CharConversionException, NoSuchAlgorithmException, InvalidKeyException, InvalidAlgorithmParameterException, CertificateEncodingException, IOException, IllegalStateException, IllegalBlockSizeException, @@ -1613,7 +1631,7 @@ public class CryptoUtil { byte[] key_data = null; //generate session key - SymmetricKey sk = CryptoUtil.generateKey(token, keyGenAlg); + SymmetricKey sk = CryptoUtil.generateKey(token, keyGenAlg, symKeySize); if (passphrase != null) { key_data = wrapPassphrase(token, passphrase, IV, sk, EncryptionAlgorithm.DES3_CBC_PAD); |