本文整理了Java中java.security.KeyStore.setEntry()
方法的一些代码示例,展示了KeyStore.setEntry()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyStore.setEntry()
方法的具体详情如下:
包路径:java.security.KeyStore
类名称:KeyStore
方法名:setEntry
[英]Stores the given Entry in this KeyStore and associates the entry with the given alias. The entry is protected by the specified ProtectionParameter.
If the specified alias already exists, it will be reassigned.
[中]将给定项存储在此密钥库中,并将该项与给定别名关联。该条目受指定的ProtectionParameter保护。
如果指定的别名已存在,将重新分配它。
代码示例来源:origin: gocd/gocd
public void storeCACertificate(File storeFile, String password, Certificate caCertificate, Registration entry)
throws Exception {
lazyLoadedStore = KeyStore.getInstance(KEYSTORE_TYPE);
loadStore(lazyLoadedStore);
lazyLoadedStore.setCertificateEntry("ca-cert", caCertificate);
lazyLoadedStore.setEntry("ca-intermediate", entry.asKeyStoreEntry(),
new KeyStore.PasswordProtection(password.toCharArray()));
writeStore(storeFile, password);
}
代码示例来源:origin: eclipse-vertx/vert.x
private static KeyStore loadKeyCert(List<Buffer> keyValue, List<Buffer> certValue) throws Exception {
if (keyValue.size() < certValue.size()) {
throw new VertxException("Missing private key");
} else if (keyValue.size() > certValue.size()) {
throw new VertxException("Missing X.509 certificate");
}
final KeyStore keyStore = createEmptyKeyStore();
Iterator<Buffer> keyValueIt = keyValue.iterator();
Iterator<Buffer> certValueIt = certValue.iterator();
int index = 0;
while (keyValueIt.hasNext() && certValueIt.hasNext()) {
PrivateKey key = loadPrivateKey(keyValueIt.next());
Certificate[] chain = loadCerts(certValueIt.next());
keyStore.setEntry("dummy-entry-" + index++, new KeyStore.PrivateKeyEntry(key, chain), new KeyStore.PasswordProtection(DUMMY_PASSWORD.toCharArray()));
}
return keyStore;
}
代码示例来源:origin: elastic/elasticsearch-hadoop
public void setSecureSetting(String alias, String key) throws EsHadoopSecurityException {
SecretKey spec = new SecretKeySpec(key.getBytes(), AES);
KeyStore.SecretKeyEntry entry = new KeyStore.SecretKeyEntry(spec);
try {
keyStore.setEntry(alias, entry, protection);
} catch (KeyStoreException e) {
throw new EsHadoopSecurityException(String.format("Could not store secret key (alias : [%s]) in keystore", alias), e);
}
}
代码示例来源:origin: wildfly/wildfly
public void engineSetEntry(final String alias, final KeyStore.Entry entry, final KeyStore.ProtectionParameter protParam) throws KeyStoreException {
if (entry instanceof PasswordEntry) try {
delegate.setEntry(alias, new KeyStore.SecretKeyEntry(encoded(((PasswordEntry) entry).getPassword())), protParam);
} catch (InvalidKeyException e) {
throw new KeyStoreException(e);
}else {
delegate.setEntry(alias, entry, protParam);
}
}
代码示例来源:origin: wildfly/wildfly
private void loadSecretKey(ObjectInputStream ois) throws IOException, GeneralSecurityException {
byte[] encryptedData = readBytes(ois);
byte[] iv = readBytes(ois);
decrypt.init(Cipher.DECRYPT_MODE, storageSecretKey, new IvParameterSpec(iv));
Assert.checkMaximumParameter("cipher block size", 256, decrypt.getBlockSize());
byte[] unPadded = pkcs7UnPad(decrypt.doFinal(encryptedData));
ObjectInputStream entryOis = new ObjectInputStream(new ByteArrayInputStream(unPadded));
String ksAlias = entryOis.readUTF();
byte[] encodedSecretKey = readBytes(entryOis);
KeyStore.Entry entry = new KeyStore.SecretKeyEntry(new SecretKeySpec(encodedSecretKey, DATA_OID));
dataKeyStore.setEntry(ksAlias, entry, convertParameter(protectionParameter));
}
代码示例来源:origin: stackoverflow.com
for (int i = 0; i < length; i++) {
Certificate certificate = certificates[i];
keyStore.setEntry(String.valueOf(i), new KeyStore.TrustedCertificateEntry(certificate),
null);
代码示例来源:origin: apache/incubator-gobblin
/**
* Generate a set of AES keys for the store. The key ids will simple be (startOffset ... startOffset + numKeys).
* @param numKeys Number of keys to generate
* @param startOffset ID to start generating keys with
* @throws IOException If there is an error serializing the keystore back to disk
* @throws KeyStoreException If there is an error serializing the keystore back to disk
*/
public void generateAesKeys(int numKeys, int startOffset) throws IOException, KeyStoreException {
for (int i = 1; i <= numKeys; i++) {
SecretKey key = generateKey();
ks.setEntry(String.valueOf(i + startOffset), new KeyStore.SecretKeyEntry(key),
new KeyStore.PasswordProtection(password));
}
saveKeystore();
}
代码示例来源:origin: geoserver/geoserver
@Override
public void setSecretKey(String alias, char[] key) throws IOException {
assertActivatedKeyStore();
SecretKey mySecretKey = new SecretKeySpec(toBytes(key), "PBE");
KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(mySecretKey);
char[] passwd = securityManager.getMasterPassword();
try {
ks.setEntry(alias, skEntry, new KeyStore.PasswordProtection(passwd));
} catch (KeyStoreException e) {
throw new IOException(e);
} finally {
securityManager.disposePassword(passwd);
}
}
代码示例来源:origin: apache/ignite
ks.setEntry(
DEFAULT_MASTER_KEY_NAME,
new KeyStore.SecretKeyEntry(key),
代码示例来源:origin: geoserver/geoserver
+ " class: "
+ key.getClass().getName());
else newKS.setEntry(alias, entry, protectionparam);
代码示例来源:origin: apache/hbase
store.setEntry(ALIAS,
new KeyStore.SecretKeyEntry(new SecretKeySpec(KEY, "AES")),
new KeyStore.PasswordProtection(PASSWORD.toCharArray()));
代码示例来源:origin: wildfly/wildfly
keyStore.setEntry(ksAlias, entry, convertParameter(protectionParameter));
final TopEntry topEntry = cache.computeIfAbsent(toLowercase(credentialAlias), TopEntry::new);
final MidEntry midEntry = topEntry.getMap().computeIfAbsent(credentialClass, c -> new MidEntry(topEntry, c));
代码示例来源:origin: io.vertx/vertx-core
private static KeyStore loadKeyCert(List<Buffer> keyValue, List<Buffer> certValue) throws Exception {
if (keyValue.size() < certValue.size()) {
throw new VertxException("Missing private key");
} else if (keyValue.size() > certValue.size()) {
throw new VertxException("Missing X.509 certificate");
}
final KeyStore keyStore = createEmptyKeyStore();
Iterator<Buffer> keyValueIt = keyValue.iterator();
Iterator<Buffer> certValueIt = certValue.iterator();
int index = 0;
while (keyValueIt.hasNext() && certValueIt.hasNext()) {
PrivateKey key = loadPrivateKey(keyValueIt.next());
Certificate[] chain = loadCerts(certValueIt.next());
keyStore.setEntry("dummy-entry-" + index++, new KeyStore.PrivateKeyEntry(key, chain), new KeyStore.PasswordProtection(DUMMY_PASSWORD.toCharArray()));
}
return keyStore;
}
代码示例来源:origin: org.drools/drools-core
private SecretKey storeKeyIntoKeyStoreFile(final String keyPhrase)
throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException,
InvalidKeyException, InvalidKeySpecException {
final KeyStore keyStore = KeyStore.getInstance("JCEKS");
keyStore.load(null, KEYSTORE_SERVER_PASSWORD.toCharArray());
final SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("DES");
final SecretKey mySecretKey = secretKeyFactory.generateSecret(new DESKeySpec(keyPhrase.getBytes()));
final KeyStore.SecretKeyEntry skEntry = new KeyStore.SecretKeyEntry(mySecretKey);
keyStore.setEntry(KEY_ALIAS, skEntry, new KeyStore.PasswordProtection(KEY_PASSWORD.toCharArray()));
try (FileOutputStream fos = new java.io.FileOutputStream(KEYSTORE_JCEKS_FILENAME, false)) {
keyStore.store(fos, KEYSTORE_SERVER_PASSWORD.toCharArray());
}
return mySecretKey;
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch-hadoop
public void setSecureSetting(String alias, String key) throws EsHadoopSecurityException {
SecretKey spec = new SecretKeySpec(key.getBytes(), AES);
KeyStore.SecretKeyEntry entry = new KeyStore.SecretKeyEntry(spec);
try {
keyStore.setEntry(alias, entry, protection);
} catch (KeyStoreException e) {
throw new EsHadoopSecurityException(String.format("Could not store secret key (alias : [%s]) in keystore", alias), e);
}
}
代码示例来源:origin: org.elasticsearch/elasticsearch-spark-13
public void setSecureSetting(String alias, String key) throws EsHadoopSecurityException {
SecretKey spec = new SecretKeySpec(key.getBytes(), AES);
KeyStore.SecretKeyEntry entry = new KeyStore.SecretKeyEntry(spec);
try {
keyStore.setEntry(alias, entry, protection);
} catch (KeyStoreException e) {
throw new EsHadoopSecurityException(String.format("Could not store secret key (alias : [%s]) in keystore", alias), e);
}
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron-credential
public void engineSetEntry(final String alias, final KeyStore.Entry entry, final KeyStore.ProtectionParameter protParam) throws KeyStoreException {
if (entry instanceof PasswordEntry) try {
delegate.setEntry(alias, new KeyStore.SecretKeyEntry(encoded(((PasswordEntry) entry).getPassword())), protParam);
} catch (InvalidKeyException e) {
throw new KeyStoreException(e);
}else {
delegate.setEntry(alias, entry, protParam);
}
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron
private void loadSecretKey(ObjectInputStream ois) throws IOException, GeneralSecurityException {
byte[] encryptedData = readBytes(ois);
byte[] iv = readBytes(ois);
decrypt.init(Cipher.DECRYPT_MODE, storageSecretKey, new IvParameterSpec(iv));
Assert.checkMaximumParameter("cipher block size", 256, decrypt.getBlockSize());
byte[] unPadded = pkcs7UnPad(decrypt.doFinal(encryptedData));
ObjectInputStream entryOis = new ObjectInputStream(new ByteArrayInputStream(unPadded));
String ksAlias = entryOis.readUTF();
byte[] encodedSecretKey = readBytes(entryOis);
KeyStore.Entry entry = new KeyStore.SecretKeyEntry(new SecretKeySpec(encodedSecretKey, DATA_OID));
dataKeyStore.setEntry(ksAlias, entry, convertParameter(protectionParameter));
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron-credential-store
private void loadSecretKey(ObjectInputStream ois) throws IOException, GeneralSecurityException {
byte[] encryptedData = readBytes(ois);
byte[] iv = readBytes(ois);
decrypt.init(Cipher.DECRYPT_MODE, storageSecretKey, new IvParameterSpec(iv));
Assert.checkMaximumParameter("cipher block size", 256, decrypt.getBlockSize());
byte[] unPadded = pkcs7UnPad(decrypt.doFinal(encryptedData));
ObjectInputStream entryOis = new ObjectInputStream(new ByteArrayInputStream(unPadded));
String ksAlias = entryOis.readUTF();
byte[] encodedSecretKey = readBytes(entryOis);
KeyStore.Entry entry = new KeyStore.SecretKeyEntry(new SecretKeySpec(encodedSecretKey, DATA_OID));
dataKeyStore.setEntry(ksAlias, entry, convertParameter(protectionParameter));
}
代码示例来源:origin: com.couchbase.client/encryption
@Override
public void storeKey(String keyName, byte[] secretKey) throws Exception {
SimpleSecretKey secretKeyEntry = new SimpleSecretKey(secretKey);
this.ks.setEntry(keyName, new KeyStore.SecretKeyEntry(secretKeyEntry), getProtection(keyName));
}
内容来源于网络,如有侵权,请联系作者删除!