当前位置: 首页>>代码示例>>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;未经允许,请勿转载。