當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyStoreException.toString方法代碼示例

本文整理匯總了Java中java.security.KeyStoreException.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyStoreException.toString方法的具體用法?Java KeyStoreException.toString怎麽用?Java KeyStoreException.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.KeyStoreException的用法示例。


在下文中一共展示了KeyStoreException.toString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doImportKeyStoreSingle

import java.security.KeyStoreException; //導入方法依賴的package包/類
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:70,代碼來源:Main.java

示例2: doImportKeyStoreSingle

import java.security.KeyStoreException; //導入方法依賴的package包/類
/**
 * Import a single entry named alias from srckeystore
 * @return  1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:74,代碼來源:Main.java


注:本文中的java.security.KeyStoreException.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。