modules/jretools/src/main/java/org/apache/harmony/jretools/keytool/KeyCertGenerator.java [508:557]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private static void generateSecretKey(KeytoolParameters param)
            throws NoSuchAlgorithmException, NoSuchProviderException,
            KeyStoreException, CertificateException, FileNotFoundException,
            IOException {

        String keyAlg = param.getKeyAlg();
        int keySize = param.getKeySize();

        if (keyAlg == null) {
            keyAlg = "DES";
        } else {
            keyAlg = getAlgNameAndOID(keyAlg)[0];
        }
        if (param.isVerbose()) {
            System.out.println("Generating a new secret key: ");
            System.out.println("Algorithm: " + keyAlg);
            System.out.println("Key size: " + keySize);
        }
        KeyGenerator keyGen;
        String keyProvider = (param.getKeyProvider() != null) ? param
                .getKeyProvider() : param.getProvider();
        try {

            if (keyProvider == null) {
                keyGen = KeyGenerator.getInstance(keyAlg);
            } else {
                keyGen = KeyGenerator.getInstance(keyAlg, keyProvider);
            }
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException("The algorithm " + keyAlg
                    + " is not found in the environment.", e);
        } catch (NoSuchProviderException e) {
            throw (NoSuchProviderException) new NoSuchProviderException(
                    "The provider " + keyProvider
                            + " is not found in the environment.").initCause(e);
        }

        keyGen.init(keySize);
        SecretKey key = keyGen.generateKey();

        KeyStore keyStore = param.getKeyStore();

        // keyStore.setKeyEntry(param.getAlias(), key, param.getKeyPass(),
        // null);

        keyStore.setEntry(param.getAlias(), new KeyStore.SecretKeyEntry(key),
                new KeyStore.PasswordProtection(param.getKeyPass()));

        param.setNeedSaveKS(true);
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/jdktools/src/main/java/org/apache/harmony/tools/keytool/KeyCertGenerator.java [508:557]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    private static void generateSecretKey(KeytoolParameters param)
            throws NoSuchAlgorithmException, NoSuchProviderException,
            KeyStoreException, CertificateException, FileNotFoundException,
            IOException {

        String keyAlg = param.getKeyAlg();
        int keySize = param.getKeySize();

        if (keyAlg == null) {
            keyAlg = "DES";
        } else {
            keyAlg = getAlgNameAndOID(keyAlg)[0];
        }
        if (param.isVerbose()) {
            System.out.println("Generating a new secret key: ");
            System.out.println("Algorithm: " + keyAlg);
            System.out.println("Key size: " + keySize);
        }
        KeyGenerator keyGen;
        String keyProvider = (param.getKeyProvider() != null) ? param
                .getKeyProvider() : param.getProvider();
        try {

            if (keyProvider == null) {
                keyGen = KeyGenerator.getInstance(keyAlg);
            } else {
                keyGen = KeyGenerator.getInstance(keyAlg, keyProvider);
            }
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException("The algorithm " + keyAlg
                    + " is not found in the environment.", e);
        } catch (NoSuchProviderException e) {
            throw (NoSuchProviderException) new NoSuchProviderException(
                    "The provider " + keyProvider
                            + " is not found in the environment.").initCause(e);
        }

        keyGen.init(keySize);
        SecretKey key = keyGen.generateKey();

        KeyStore keyStore = param.getKeyStore();

        // keyStore.setKeyEntry(param.getAlias(), key, param.getKeyPass(),
        // null);

        keyStore.setEntry(param.getAlias(), new KeyStore.SecretKeyEntry(key),
                new KeyStore.PasswordProtection(param.getKeyPass()));

        param.setNeedSaveKS(true);
    }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



