本文整理汇总了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;
}
}
示例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;
}
}