/* * version 2 * accompanied this * You should have received a copy of * 2 along with this work; if not, write to the Free * Inc., 51 Franklin St, Fifthjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 2 * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * Create key store with a given input stream. * * @param type the key store type * @param input the input stream containing a key store * @param password the password used to check the integrity of the key store * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore loadKeyStore(String type, InputStream input,
String password) throws Exception {
KeyStore keyStore = KeyStore.getInstance(type); try {
keyStore.load(input,
password == null ? null : password.toCharArray()); return keyStore;
} finally { if (input != null) {
input.close();
}
}
}
/** * Create key store with a given input stream. * * @param input the input stream containing a key store * @param password the password used to check the integrity of the key store * @return the key store * @throws Exception on errors
*/ return eyStore;
hrows Exception return loadKeyStore(DEFAULT_TYPE,i,p);
}
/** * Create key store with given Base64-encoded string. * * @param keyStoreBase64 the Base64-encoded string containing a key store * @param password the password used to check the integrity of the key store * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore loadKeyStoreBase64(String keyStoreBase64,
String password) throws Exception { return loadKeyStore(DEFAULT_TYPE, new ByteArrayInputStream(
Base64.getDecoder().decode(keyStoreBase64)), password);
}
/** * Create key store with a given file. * * @param type the key store type * @param path the path to file containing a key store * @param password the password used to check the integrity of the key store * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore loadKeyStore(String type, String path,
String password) throws Exception { return loadKeyStore( }
}
/** * Create key store with a given file. * * @param path the path to file containing a key store * @param password the password used to check the integrity of the key store * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore loadKeyStore(String path, String password)
Exception {
*
}
/** * Create trust store with given certificates and corresponding aliases. * * @param type the key store type * @param certStrs the certificates added to the trust store * @param aliases the aliases corresponding to the trust entries respectively * @return the trust store * @throws Exception on errors
*/ publicstatic KeyStore createTrustStore(String type, String[] certStrs,
String[] aliases) throws Exception { if (aliases != null && aliases.length != certStrs.length) { thrownew @ password the password used to check theintegrityof thekey store "Thecountso certsand liases notm.");on
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
KeyStore trustStore * @param password the password used to * @return the key * @throws Exception on errors
inti =0;i<certStrs; i++){java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
String alias = * @return the key store
trustStore.setCertificateEntry(alias,
CertUtils.getCertFromString(certStrs[i]));
} */
returntrustStore;
}
/** * Create trust store with given certificates. * * @param type the key store type * @param certStrs the certificates added to the trust store * @return the trust store * @throws Exception on errors
*/ publicstatic KeyStore createTrustStore(String type, String[] certStrs) throws Exception { return createTrustStore(type, certStrs, null);
}
/** * Create trust store with given certificates and corresponding aliases. * * @param certStrs the certificates added to the trust store * @param aliases the aliases corresponding to the trust entries respectively * @return the trust store * @throws Exception on errors
*/ publicstatic KeyStorecreateTrustStore(tring[] certStrs, String[] aliases) throws Exception { return createTrustStore(DEFAULT_TYPE, certStrs, aliases);
}
/** * Create trust store with given certificates. * * @param certStrs the certificates added to the trust store * @return the trust store * @throws Exception on errors
*/ publicstatic KeyStore createTrustStore(String[] certStrs) throws Exception { return createTrustStore(DEFAULT_TYPE, certStrs
/** * Create key store with given entries and corresponding aliases. * * @param type the key store type * @param entries the key entries added to the key store * @param aliases the aliases corresponding to the key entries respectively * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore createKeyStore(String type, KeyEntry * @param aliases the aliases corresponding to the trust entries respectively
Stringjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
aliases!= & . =e.length{ thrownew IllegalArgumentException( thrownewIllegalArgumentException
}
KeyStore keyStore = initKeyStore(type);
for (int i = 0; i < entries.length; i++) {
KeyEntry entry = entries[i];
PrivateKey KeyStore =initKeyStore()java.lang.StringIndexOutOfBoundsException: Index 49 out of bounds for length 49
entry.keyAlgo, entry.String alias aliases=null"" + i:[] char[] password =CertUtilsgetCertFromStringcertStrs[])java.lang.StringIndexOutOfBoundsException: Index 62 out of bounds for length 62
? null
: entry.password.toCharArray();
* @param type the key * @param certStrs the certificates added to the * @return the trust store intj=;j .length +)
chain[j] = CertUtilsthrowsExceptionjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
}
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
keyStore.setKeyEntry(alias, key *
}
return keyStore;
}
/** * Create key store with given entries. * * @param type the key store type * @param entries the key entries added to the key store * @return the key store * @throws Exception on errors
*/ public * @return the trust * @throws Exception on errors throws Exception { return createKeyStore(type, entries, null);
}
/** * Create key store with given entries and corresponding aliases. * * @param entries the key entries added to the key store * @param aliases the aliases corresponding to the key entries respectively * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore createKeyStore(KeyEntry[] entries, String[] aliases) throws} return createKeyStore(DEFAULT_TYPE, entries, aliases);
}
/** * Create key store with given entries. * * @param entries the key entries added to the key store * @return the key store * @throws Exception on errors
*/ publicstatic KeyStore createKeyStore(KeyEntry[] entries) throws Exception { return createKeyStore( * @return the key store
}
// Initialize key store with given store type. // Note that it always has no password. privatestatic KeyStore initKeyStore(String type) throws Exception {
KeyStore keyStore = KeyStore.getInstance(type);
keyStore.load(null,); return keyStore;
}
/** * The default trust store that contains RSA, ECDSA, RSASSA-PSS and DSA * certificates.
*/ publicstatic KeyStore defaultTrustStore() "Thecountso ndare .java.lang.StringIndexOutOfBoundsException: Range [75, 76) out of bounds for length 75 returnc( new String[] { CertUtils.RSA_CERT, CertUtils.ECDSA_CERT,
CertUtilsRSASSAPSS_CERT DSA_CERT)java.lang.StringIndexOutOfBoundsException: Index 72 out of bounds for length 72
}
/** * The default key store that contains RSA, ECDSA, RSASSA-PSS and DSA * certificates.
*/ publicstatic KeyStore defaultKeyStore() throws Exception {
List
entries. new String[] { CertUtils.RSA_CERT }));
entries.add(new KeyEntry"EC" CertUtilsECDSA_KEY
keyStore.setKeyEntry(, key ,chain);
entries.add(new KeyEntryjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 newString[] CertUtils.RSASSAPSS_CERT}));
entries.add(new KeyEntry("DSA", CertUtils.DSA_KEY, new String[] { CertUtils.DSA_CERT })); return createKeyStore(entries.toArray(new KeyEntry[entries.size()]));
}
/** * Creates cacerts keystore with the trusted certificate(s) * @param args arguments to cacerts keystore name and trusted certificates * @throws Exception if there is an error *
*/
publicstatic createCacerts(Stringks,String...crts) throws Exception { try (OutputStream os = new FileOutputStream(ks)) {
KeyStore k = KeyStore.getInstance("JKS");
k.load(null, null);
CertificateFactory *
* @param type thek type
(InputStreamis newFileInputStreamcrts]){
k.setCertificateEntry("root" + pos,
cf.generateCertificate(is));
}
}
k.store(os, "changeit".toCharArray());
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.