modules/jdktools/src/main/java/org/apache/harmony/tools/keytool/EntryManager.java [35:124]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class EntryManager {
    /**
     * Copies the key and the certificate chain (if any) from the keystore entry
     * identified by given alias into a newly created one with given destination
     * alias. alias and destination alias are specified in param.
     * 
     * @param param
     * @throws UnrecoverableKeyException
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws KeytoolException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     */
    static void keyClone(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            KeytoolException, CertificateException, FileNotFoundException,
            NoSuchProviderException, IOException {
        KeyStore keyStore = param.getKeyStore();
        String alias = param.getAlias();
        Key srcKey;
        try {
            srcKey = keyStore.getKey(alias, param.getKeyPass());
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }
        // if the entry is a not a KeyEntry
        if (srcKey == null) {
            throw new KeytoolException("The entry <" + alias + "> has no key.");
        }
        Certificate[] certChain = keyStore
                .getCertificateChain(param.getAlias());
        keyStore.setKeyEntry(param.getDestAlias(), srcKey,
                param.getNewPasswd(), certChain);
        param.setNeedSaveKS(true);
    }

    /**
     * Removes from the keystore the entry associated with alias.
     * 
     * @param param
     * @throws KeyStoreException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     * @throws NoSuchAlgorithmException 
     */
    static void delete(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException,
            FileNotFoundException, NoSuchProviderException, IOException {
        param.getKeyStore().deleteEntry(param.getAlias());
        param.setNeedSaveKS(true);
    }

    /**
     * Changes the key password to the new one.
     * 
     * @param param
     * @throws KeyStoreException
     * @throws NoSuchAlgorithmException
     * @throws UnrecoverableKeyException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     */
    static void keyPasswd(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            CertificateException, FileNotFoundException,
            NoSuchProviderException, IOException {
        KeyStore keyStore = param.getKeyStore();
        String alias = param.getAlias();
        Key key;
        Certificate[] chain;
        try {
            key = keyStore.getKey(alias, param.getKeyPass());
            chain = keyStore.getCertificateChain(alias);
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }

        keyStore.deleteEntry(alias);
        keyStore.setKeyEntry(alias, key, param.getNewPasswd(), chain);
        param.setKeyPass(param.getNewPasswd());
        param.setNeedSaveKS(true);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/jretools/src/main/java/org/apache/harmony/jretools/keytool/EntryManager.java [35:124]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class EntryManager {
    /**
     * Copies the key and the certificate chain (if any) from the keystore entry
     * identified by given alias into a newly created one with given destination
     * alias. alias and destination alias are specified in param.
     * 
     * @param param
     * @throws UnrecoverableKeyException
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws KeytoolException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     */
    static void keyClone(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            KeytoolException, CertificateException, FileNotFoundException,
            NoSuchProviderException, IOException {
        KeyStore keyStore = param.getKeyStore();
        String alias = param.getAlias();
        Key srcKey;
        try {
            srcKey = keyStore.getKey(alias, param.getKeyPass());
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }
        // if the entry is a not a KeyEntry
        if (srcKey == null) {
            throw new KeytoolException("The entry <" + alias + "> has no key.");
        }
        Certificate[] certChain = keyStore
                .getCertificateChain(param.getAlias());
        keyStore.setKeyEntry(param.getDestAlias(), srcKey,
                param.getNewPasswd(), certChain);
        param.setNeedSaveKS(true);
    }

    /**
     * Removes from the keystore the entry associated with alias.
     * 
     * @param param
     * @throws KeyStoreException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     * @throws NoSuchAlgorithmException 
     */
    static void delete(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, CertificateException,
            FileNotFoundException, NoSuchProviderException, IOException {
        param.getKeyStore().deleteEntry(param.getAlias());
        param.setNeedSaveKS(true);
    }

    /**
     * Changes the key password to the new one.
     * 
     * @param param
     * @throws KeyStoreException
     * @throws NoSuchAlgorithmException
     * @throws UnrecoverableKeyException
     * @throws IOException 
     * @throws NoSuchProviderException 
     * @throws FileNotFoundException 
     * @throws CertificateException 
     */
    static void keyPasswd(KeytoolParameters param) throws KeyStoreException,
            NoSuchAlgorithmException, UnrecoverableKeyException,
            CertificateException, FileNotFoundException,
            NoSuchProviderException, IOException {
        KeyStore keyStore = param.getKeyStore();
        String alias = param.getAlias();
        Key key;
        Certificate[] chain;
        try {
            key = keyStore.getKey(alias, param.getKeyPass());
            chain = keyStore.getCertificateChain(alias);
        } catch (NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(
                    "Cannot find the algorithm to recover the key. ", e);
        }

        keyStore.deleteEntry(alias);
        keyStore.setKeyEntry(alias, key, param.getNewPasswd(), chain);
        param.setKeyPass(param.getNewPasswd());
        param.setNeedSaveKS(true);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



