本文整理汇总了Java中java.security.KeyStore.ProtectionParameter类的典型用法代码示例。如果您正苦于以下问题:Java ProtectionParameter类的具体用法?Java ProtectionParameter怎么用?Java ProtectionParameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtectionParameter类属于java.security.KeyStore包,在下文中一共展示了ProtectionParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: performLoad
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
protected void performLoad ( final CallbackHandler callbackHandler ) throws Exception
{
this.list.clear ();
setLocked ( true );
this.keyStore.load ( new KeyStore.LoadStoreParameter () {
@Override
public ProtectionParameter getProtectionParameter ()
{
return new KeyStore.CallbackHandlerProtection ( new CallbackHandlerTranslator ( callbackHandler ) );
}
} );
setLocked ( false );
extractKeys ( null );
}
示例2: addPrivateKey
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/**
* Asymmetric cryptography - only the private key from generated pair is used.
* Pre-condition: #certificateAlias refers to existing certificate
*
* @throws {@link NullPointerException} when #certificateAlias is @code{null}
*/
public void addPrivateKey(String keyAlias, String certificateAlias, String password) {
keyAlias = String.format("%s (%s)", keyAlias, certificateAlias);
try {
Certificate[] certChain = keystore.getCertificateChain(certificateAlias);
if (certChain == null) {
LoggerFactory.getLogger(getClass()).warn("Could not find certificate");
certChain = new Certificate[0];
}
Entry entry = new PrivateKeyEntry(generateKeyPair().getPrivate(), certChain);
ProtectionParameter protParam = new KeyStore.PasswordProtection(password.toCharArray());
keystore.setEntry(keyAlias, entry, protParam);
} catch (KeyStoreException | NoSuchAlgorithmException ex) {
throw new RuntimeException("Unable to add new private key", ex);
}
}
示例3: engineGetEntry
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public KeyStore.Entry engineGetEntry(final String alias,
final ProtectionParameter protParam) {
if (protParam instanceof KeyStore.PasswordProtection) {
final PasswordCallback pwc = new CachePasswordCallback(((KeyStore.PasswordProtection)protParam).getPassword());
this.cryptoCard.setPasswordCallback(pwc);
}
if (!engineContainsAlias(alias)) {
return null;
}
final PrivateKey key = (PrivateKey) engineGetKey(
alias,
null // Le pasamos null porque ya hemos establecido el PasswordCallback o el CallbackHander antes
);
return new PrivateKeyEntry(key, engineGetCertificateChain(alias));
}
示例4: getKeyProtection
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
@Override
protected final KeyStore.ProtectionParameter getKeyProtection(
final String entryAlias,
final X509Certificate entryCert,
final KeyEntryPasswordProvider entryPasswordProvider)
{
if (null == entryPasswordProvider)
{
return null;
}
return new KeyStore.CallbackHandlerProtection(new CallbackHandler()
{
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
{
PasswordCallback c = (PasswordCallback) callbacks[0];
c.setPassword(entryPasswordProvider.getPassword(entryAlias, entryCert));
}
});
}
示例5: FileSystemKeyStoreKeyingDataProvider
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/**
* @param keyStoreType the type of the keystore (jks, pkcs12, etc)
* @param keyStorePath the file-system path of the keystore
* @param certificateSelector the selector of signing certificate
* @param keyStorePasswordProvider the provider of the keystore loading password
* @param entryPasswordProvider the provider of entry passwords
* @param returnFullChain indicates of the full certificate chain should be returned, if available
* @throws KeyStoreException
*/
public FileSystemKeyStoreKeyingDataProvider(
final String keyStoreType,
final String keyStorePath,
SigningCertSelector certificateSelector,
KeyStorePasswordProvider keyStorePasswordProvider,
KeyEntryPasswordProvider entryPasswordProvider,
boolean returnFullChain) throws KeyStoreException
{
super(new KeyStoreBuilderCreator()
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
return KeyStore.Builder.newInstance(
keyStoreType,
null,
new File(keyStorePath),
loadProtection);
}
},
certificateSelector,
keyStorePasswordProvider,
entryPasswordProvider,
returnFullChain);
}
示例6: engineGetEntry
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
@Override
public Entry engineGetEntry(String alias, ProtectionParameter protParam)
throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
LOGGER.debug("engineGetEntry: {}", alias);
if ("Authentication".equals(alias) || "Signature".equals(alias)) {
PrivateKey privateKey = (PrivateKey) engineGetKey(alias, null);
Certificate[] chain = engineGetCertificateChain(alias);
PrivateKeyEntry privateKeyEntry = new PrivateKeyEntry(privateKey, chain);
return privateKeyEntry;
}
if ("CA".equals(alias) || "Root".equals(alias) || "RRN".equals(alias)) {
Certificate certificate = engineGetCertificate(alias);
TrustedCertificateEntry trustedCertificateEntry = new TrustedCertificateEntry(certificate);
return trustedCertificateEntry;
}
return super.engineGetEntry(alias, protParam);
}
示例7: engineLoad
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
@Override
public void engineLoad(LoadStoreParameter param) throws IOException,
NoSuchAlgorithmException, CertificateException {
if (param == null) {
engineLoad(null, null);
return;
}
ProtectionParameter pParam = param.getProtectionParameter();
if (pParam == null) {
throw new NoSuchAlgorithmException();
}
if (pParam instanceof PasswordProtection) {
char[] password = ((PasswordProtection) pParam).getPassword();
if (password == null) {
throw new NoSuchAlgorithmException();
} else {
return;
}
}
throw new CertificateException();
}
示例8: engineStore
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
@Override
public void engineStore(LoadStoreParameter param) throws IOException,
NoSuchAlgorithmException, CertificateException {
if (param == null) {
throw new IOException();
}
ProtectionParameter pParam = param.getProtectionParameter();
if (pParam instanceof PasswordProtection) {
char[] password = ((PasswordProtection) pParam).getPassword();
if (password == null) {
throw new NoSuchAlgorithmException();
} else if (password.length == 0) {
throw new CertificateException();
}
return;
}
throw new UnsupportedOperationException();
}
示例9: test_getKeyStore
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
public void test_getKeyStore() throws KeyStoreException,
NoSuchAlgorithmException, CertificateException,
FileNotFoundException, IOException {
String alias = "BKS";
char[] pwd = new char[] { '1', '2', '3', '4', '5', '6' };
InputStream fis = KeyStore2Test.class
.getResourceAsStream("builderimpl.ks");
KeyStore ks = KeyStore.getInstance(alias);
ks.load(fis, pwd);
Builder b = Builder.newInstance(ks, new PasswordProtection(pwd));
KeyStore firstKeyStore = b.getKeyStore();
ProtectionParameter firstProtParameter = b
.getProtectionParameter(alias);
assertSame(firstKeyStore, b.getKeyStore());
assertSame(firstProtParameter, b.getProtectionParameter(alias));
b = Builder.newInstance(alias, ks.getProvider(),
new KeyStore.PasswordProtection(pwd));
firstKeyStore = b.getKeyStore();
firstProtParameter = b.getProtectionParameter(alias);
assertNotSame(firstKeyStore, b.getKeyStore());
assertSame(firstProtParameter, b.getProtectionParameter(alias));
}
示例10: engineLoad
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void engineLoad(final KeyStore.LoadStoreParameter param) throws IOException {
if (param != null) {
final ProtectionParameter pp = param.getProtectionParameter();
if (pp instanceof KeyStore.CallbackHandlerProtection) {
if (((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler() == null) {
throw new IllegalArgumentException("El CallbackHandler no puede ser nulo"); //$NON-NLS-1$
}
this.cryptoCard = new Ceres(
CeresProvider.getDefaultApduConnection(),
new JseCryptoHelper()
);
this.cryptoCard.setCallbackHandler(((KeyStore.CallbackHandlerProtection) pp).getCallbackHandler());
}
else if (pp instanceof KeyStore.PasswordProtection) {
final PasswordCallback pwc = new CeresPasswordCallback((PasswordProtection) pp);
this.cryptoCard = new Ceres(
CeresProvider.getDefaultApduConnection(),
new JseCryptoHelper()
);
this.cryptoCard.setPasswordCallback(pwc);
}
else {
Logger.getLogger("es.gob.jmulticard").warning( //$NON-NLS-1$
"Se ha proporcionado un LoadStoreParameter de tipo no soportado, se ignorara: " + (pp != null ? pp.getClass().getName() : "NULO") //$NON-NLS-1$ //$NON-NLS-2$
);
}
}
else {
this.cryptoCard = new Ceres(
CeresProvider.getDefaultApduConnection(),
new JseCryptoHelper()
);
}
userCertAliases = Arrays.asList(this.cryptoCard.getAliases());
}
示例11: engineGetEntry
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public KeyStore.Entry engineGetEntry(final String alias,
final ProtectionParameter protParam) {
if(protParam instanceof KeyStore.CallbackHandlerProtection) {
// Establecemos el CallbackHandler
final CallbackHandler chp = ((KeyStore.CallbackHandlerProtection) protParam).getCallbackHandler();
if(chp != null) {
this.cryptoCard.setCallbackHandler(chp);
}
}
else if (protParam instanceof KeyStore.PasswordProtection) {
// Establecemos el PasswordCallback
final PasswordCallback pwc = new CachePasswordCallback(((KeyStore.PasswordProtection)protParam).getPassword());
this.cryptoCard.setPasswordCallback(pwc);
}
else {
LOGGER.warning(
"Se ha proporcionado un ProtectionParameter de tipo no soportado, se ignorara: " + (protParam != null ? protParam.getClass().getName() : "NULO") //$NON-NLS-1$ //$NON-NLS-2$
);
}
if (!engineContainsAlias(alias)) {
return null;
}
final PrivateKey key = (PrivateKey) engineGetKey(
alias,
null // Le pasamos null porque ya hemos establecido el PasswordCallback o el CallbackHander antes
);
return new PrivateKeyEntry(key, engineGetCertificateChain(alias));
}
示例12: createAndLoadDynamicKeystore
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
public static KeyStore createAndLoadDynamicKeystore(RSAPrivateKey rsaPrivateKey, Certificate certificate) throws KeyManagementException {
logger.debug("Generating Keystore from RSA private key and X509 certificate");
Certificate[] certificateChain = { certificate };
PrivateKeyEntry privateKeyEntry = new KeyStore.PrivateKeyEntry(rsaPrivateKey, certificateChain);
ProtectionParameter protectionParameter = new KeyStore.PasswordProtection(KEY_PASSWORD);
KeyStore keystore = null;
try {
keystore = KeyStore.getInstance(KEYSTORE_INSTANCE_TYPE);
keystore.load(null, null);
keystore.setEntry(KEYSTORE_ALIAS, privateKeyEntry, protectionParameter);
} catch (NoSuchAlgorithmException | CertificateException | IOException | KeyStoreException ex) {
throw new KeyManagementException(ex);
}
return keystore;
}
示例13: KeyStoreProvider
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/**
* Creates an instance of this class using {@code wrappingAlgorithm} which will encrypt data to
* the keys specified by {@code aliasNames}.
*/
public KeyStoreProvider(final KeyStore keystore, final ProtectionParameter protection,
final String providerName, final String wrappingAlgorithm, final String... aliasNames) {
keystore_ = keystore;
protection_ = protection;
wrappingAlgorithm_ = wrappingAlgorithm;
aliasNames_ = Arrays.asList(aliasNames);
providerName_ = providerName;
keyAlgorithm_ = wrappingAlgorithm.split("/", 2)[0].toUpperCase();
}
示例14: PKCS11KeyStoreKeyingDataProvider
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
/**
* The provider name is used as a key to search for installed providers. If a
* provider exists with the same name, it will be used even if it relies on a
* different native library.
* @param nativeLibraryPath the path for the native library of the specific PKCS#11 provider
* @param providerName this string is concatenated with the prefix SunPKCS11- to produce this provider instance's name
* @param slotId the id of the slot that this provider instance is to be associated with (can be {@code null})
* @param certificateSelector the selector of signing certificate
* @param keyStorePasswordProvider the provider of the keystore loading password (can be {@code null})
* @param entryPasswordProvider the provider of entry passwords (may be {@code null})
* @param returnFullChain indicates of the full certificate chain should be returned, if available
* @throws KeyStoreException
*/
public PKCS11KeyStoreKeyingDataProvider(
final String nativeLibraryPath,
final String providerName,
final Integer slotId,
SigningCertSelector certificateSelector,
KeyStorePasswordProvider keyStorePasswordProvider,
KeyEntryPasswordProvider entryPasswordProvider,
boolean returnFullChain) throws KeyStoreException
{
super(new KeyStoreBuilderCreator()
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
Provider p = getInstalledProvider(providerName);
if (p == null)
{
StringBuilder config = new StringBuilder("name = ").append(providerName);
config.append(System.getProperty("line.separator"));
config.append("library = ").append(nativeLibraryPath);
if(slotId != null)
{
config.append(System.getProperty("line.separator"));
config.append("slot = ").append(slotId);
}
ByteArrayInputStream configStream = new ByteArrayInputStream(config.toString().getBytes());
p = createPkcs11Provider(configStream);
Security.addProvider(p);
}
return KeyStore.Builder.newInstance("PKCS11", p, loadProtection);
}
}, certificateSelector, keyStorePasswordProvider, entryPasswordProvider, returnFullChain);
}
示例15: getKeyProtection
import java.security.KeyStore.ProtectionParameter; //导入依赖的package包/类
@Override
protected KeyStore.ProtectionParameter getKeyProtection(
String entryAlias,
X509Certificate entryCert,
KeyEntryPasswordProvider entryPasswordProvider)
{
return new KeyStore.PasswordProtection(entryPasswordProvider.getPassword(entryAlias, entryCert));
}