• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java PasswordProtection类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中java.security.KeyStore.PasswordProtection的典型用法代码示例。如果您正苦于以下问题:Java PasswordProtection类的具体用法?Java PasswordProtection怎么用?Java PasswordProtection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



PasswordProtection类属于java.security.KeyStore包,在下文中一共展示了PasswordProtection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: loadPfx

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
public void loadPfx(InputStream is, String password)
		throws NoSuchAlgorithmException,
			CertificateException,
			IOException,
			KeyStoreException,
			UnrecoverableEntryException {

	char[] pwd = password.toCharArray();
	KeyStore keyStore = KeyStore.getInstance("pkcs12");
	keyStore.load(is, pwd);
	PasswordProtection passwordProtection = new KeyStore.PasswordProtection(pwd);

	for (Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements();) {
		String alias = aliases.nextElement();
		KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) keyStore.getEntry(alias, passwordProtection);
		Certificate cert = entry.getCertificate();
		if (cert.getType().equals("X.509")) {
			this.certificate = (X509Certificate) cert;
			this.privateKey = entry.getPrivateKey();
			return;
		}
	}
	throw new RuntimeException("Certificate of type X.509 was not found.");

}
 
开发者ID:EixoX,项目名称:jetfuel,代码行数:26,代码来源:X509CertificateWithKey.java


示例2: printAliasesList

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
public void printAliasesList(String keyPasswd) {
	try {
		System.out.println("trustStoreType=" + trustStore.getType());
		System.out.println("size=" + trustStore.size());

		// --- Get All TrustStore's Certificates Alias -----------
		Enumeration<String> enumeration = trustStore.aliases();
		while (enumeration.hasMoreElements()) {
			String alias = enumeration.nextElement();
			System.out.println("alias=" + alias);
			// Entry entry = trustStore.getEntry(alias, null);

			Entry entry = trustStore.getEntry(alias, new PasswordProtection(keyPasswd.toCharArray()));

			System.out.println("entryClass=" + entry.getClass());
		}
	} catch (KeyStoreException | NoSuchAlgorithmException | UnrecoverableEntryException e) {
		e.printStackTrace();
	}
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:21,代码来源:KeyStoreController.java


示例3: addSelfSignedCertificate

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
public void addSelfSignedCertificate(String certificateAlias, String dn, String password) {
	try {
		KeyPair keys = generateKeyPair();

		Calendar start = Calendar.getInstance();
		Calendar expiry = Calendar.getInstance();
		expiry.add(Calendar.YEAR, 1);
		X500Name name = new X500Name(dn);
		X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(name, BigInteger.ONE,
				start.getTime(), expiry.getTime(), name, SubjectPublicKeyInfo.getInstance(keys.getPublic().getEncoded()));
		ContentSigner signer = new JcaContentSignerBuilder("SHA1WithRSA").setProvider(new BouncyCastleProvider()).build(keys.getPrivate());
		X509CertificateHolder holder = certificateBuilder.build(signer);
		Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

		Entry entry = new PrivateKeyEntry(keys.getPrivate(), new Certificate[]{ cert });
		keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
	} catch (GeneralSecurityException | OperatorCreationException ex) {
		throw new RuntimeException("Unable to generate self-signed certificate", ex);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:21,代码来源:XTFKeyStore.java


示例4: addPrivateKey

import java.security.KeyStore.PasswordProtection; //导入依赖的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);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:23,代码来源:XTFKeyStore.java


示例5: engineGetEntry

import java.security.KeyStore.PasswordProtection; //导入依赖的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));
  }
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:18,代码来源:CeresKeyStoreImpl.java


示例6: setKey

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
private static void setKey(KeyStore keyStore, String keyName, String keyPassword, String keyValue) {
	if (StringUtils.isBlank(keyName)) {
		keyName = DEFAULT_KEY_NAME;
	}
	if (keyPassword == null) {
		keyPassword = DEFAULT_KEY_PASSWORD;
	}
	try {
		SecretKey secretKey = new SecretKeySpec(keyValue.getBytes(KEY_VALUE_ENCODING), KEY_TYPE);

		KeyStore.SecretKeyEntry keyStoreEntry = new KeyStore.SecretKeyEntry(secretKey);
		PasswordProtection _keyPassword = new PasswordProtection(keyPassword.toCharArray());
		keyStore.setEntry(keyName, keyStoreEntry, _keyPassword);

	} catch (Exception e) {
		throw new PaxmlRuntimeException(e);
	}

}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:20,代码来源:CryptoUtils.java


示例7: engineLoad

import java.security.KeyStore.PasswordProtection; //导入依赖的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();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:24,代码来源:TestKeyStoreSpi.java


示例8: engineStore

import java.security.KeyStore.PasswordProtection; //导入依赖的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();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:20,代码来源:TestKeyStoreSpi.java


示例9: test_getKeyStore

import java.security.KeyStore.PasswordProtection; //导入依赖的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));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:25,代码来源:KeyStore3Test.java


示例10: loadCAKeyEntry

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
private PrivateKeyEntry loadCAKeyEntry() throws IOException,
        GeneralSecurityException {
    final KeyStore keystore = loadKeyStore();
    final Entry entry = keystore.getEntry(this.alias,
            new PasswordProtection(this.password.toCharArray()));
    return (PrivateKeyEntry) entry;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:8,代码来源:SignTask.java


示例11: loadPrivateKeyEntry

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
private void loadPrivateKeyEntry() throws GeneralSecurityException {
    rootPrivateKeyEntry = (PrivateKeyEntry) rootCaKeystore.getEntry(
            rootCaAlias,
            new PasswordProtection(rootCaPassword.toCharArray()));

    if (rootPrivateKeyEntry == null) {
        throw new RuntimeException(
                "Could not read private key entry from rootca keystore with alias "
                        + rootCaAlias);
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:12,代码来源:CertificateHandler.java


示例12: addSignedCertificate

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
public void addSignedCertificate(final XTFKeyStore signerKeyStore, final String signerAlias, final String signerPassword, final String dn, final String certificateAlias, final String password) {
	try {
		final X509Certificate caCert = (X509Certificate) signerKeyStore.keystore.getCertificate(signerAlias);
		final PrivateKey caKey = (PrivateKey) signerKeyStore.keystore.getKey(signerAlias, signerPassword.toCharArray());
		final Calendar start = Calendar.getInstance();
		final Calendar expiry = Calendar.getInstance();
		expiry.add(Calendar.YEAR, 1);
		final KeyPair keyPair = generateKeyPair();
		final X500Name certName = new X500Name(dn);
		final X500Name issuerName = new X500Name(caCert.getSubjectDN().getName());
		X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
				issuerName,
				BigInteger.valueOf(System.nanoTime()),
				start.getTime(),
				expiry.getTime(),
				certName,
				SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded()));
		final JcaX509ExtensionUtils u = new JcaX509ExtensionUtils();
		certificateBuilder.addExtension(Extension.authorityKeyIdentifier, false,
				u.createAuthorityKeyIdentifier(caCert));
		certificateBuilder.addExtension(Extension.subjectKeyIdentifier, false,
				u.createSubjectKeyIdentifier(keyPair.getPublic()));
		ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSA").setProvider(new BouncyCastleProvider()).build(caKey);
		X509CertificateHolder holder = certificateBuilder.build(signer);
		Certificate cert = new JcaX509CertificateConverter().setProvider(new BouncyCastleProvider()).getCertificate(holder);

		Entry entry = new PrivateKeyEntry(keyPair.getPrivate(), new Certificate[] {cert, caCert});
		keystore.setEntry(certificateAlias, entry, new PasswordProtection(password.toCharArray()));
	} catch (GeneralSecurityException | OperatorCreationException | CertIOException ex) {
		throw new RuntimeException("Unable to generate signed certificate", ex);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:33,代码来源:XTFKeyStore.java


示例13: CeresPasswordCallback

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
/** Callback para solicitar la constrasena.
 * @param pp PasswordProtection para solicitar la constrasena.
 */
CeresPasswordCallback(final PasswordProtection pp) {
	super("Por favor, introduzca el PIN de la tarjeta CERES", false); //$NON-NLS-1$
	if (pp == null) {
		throw new IllegalArgumentException(
			"El PasswordProtection no puede ser nulo" //$NON-NLS-1$
		);
	}
	this.passp = pp;
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:13,代码来源:CeresPasswordCallback.java


示例14: engineLoad

import java.security.KeyStore.PasswordProtection; //导入依赖的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());
 }
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:39,代码来源:CeresKeyStoreImpl.java


示例15: DniePasswordCallback

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
/**
 * @param pp PasswordProtection para solicitar la contraseña
 */
DniePasswordCallback(final PasswordProtection pp) {
	super("Por favor, introduzca el PIN del DNIe", false); //$NON-NLS-1$
	if (pp == null) {
		throw new IllegalArgumentException(
			"El PasswordProtection no puede ser nulo" //$NON-NLS-1$
		);
	}
	this.passp = pp;
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:13,代码来源:DniePasswordCallback.java


示例16: engineGetEntry

import java.security.KeyStore.PasswordProtection; //导入依赖的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));
  }
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:32,代码来源:DnieKeyStoreImpl.java


示例17: test_init_Builder

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
@Test
public void test_init_Builder() {
    TestKeyStore testKeyStore = TestKeyStore.getClient();
    Builder builder = Builder.newInstance(
            testKeyStore.keyStore, new PasswordProtection(testKeyStore.storePassword));
    KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(builder);
    assertNotNull(ksbp);
    assertNotNull(ksbp.getParameters());
    assertEquals(1, ksbp.getParameters().size());
    assertSame(builder, ksbp.getParameters().get(0));
}
 
开发者ID:google,项目名称:conscrypt,代码行数:12,代码来源:KeyStoreBuilderParametersTest.java


示例18: test_init_List

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
@Test
public void test_init_List() {
    TestKeyStore testKeyStore1 = TestKeyStore.getClient();
    TestKeyStore testKeyStore2 = TestKeyStore.getServer();
    Builder builder1 = Builder.newInstance(
            testKeyStore1.keyStore, new PasswordProtection(testKeyStore1.storePassword));
    Builder builder2 = Builder.newInstance(
            testKeyStore2.keyStore, new PasswordProtection(testKeyStore2.storePassword));

    List<Builder> list = Arrays.asList(builder1, builder2);
    KeyStoreBuilderParameters ksbp = new KeyStoreBuilderParameters(list);
    assertNotNull(ksbp);
    assertNotNull(ksbp.getParameters());
    assertNotSame(list, ksbp.getParameters());
    assertEquals(2, ksbp.getParameters().size());
    assertSame(builder1, ksbp.getParameters().get(0));
    assertSame(builder2, ksbp.getParameters().get(1));

    // confirm result is not modifiable
    try {
        ksbp.getParameters().set(0, builder2);
        fail();
    } catch (UnsupportedOperationException expected) {
        // Ignored.
    }

    // confirm result is a copy of original
    list.set(0, builder2);
    assertSame(builder1, ksbp.getParameters().get(0));
}
 
开发者ID:google,项目名称:conscrypt,代码行数:31,代码来源:KeyStoreBuilderParametersTest.java


示例19: initKeystore

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
private void initKeystore(final InputStream ksStream, final String ksType, final String ksPassword) {
	try {
		keyStore = KeyStore.getInstance(ksType);
		final char[] password = (ksPassword == null) ? null : ksPassword.toCharArray();
		keyStore.load(ksStream, password);
		passwordProtection = new PasswordProtection(password);
	} catch (GeneralSecurityException | IOException e) {
		throw new DSSException("Unable to initialize the keystore", e);
	} finally {
		Utils.closeQuietly(ksStream);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:13,代码来源:KeyStoreCertificateSource.java


示例20: engineLoad

import java.security.KeyStore.PasswordProtection; //导入依赖的package包/类
@Override
public void engineLoad(InputStream file, char[] pin) throws IOException,
		NoSuchAlgorithmException, CertificateException
{
	if (file != null)
		throw new IOException ("PKCS11 Key Store requires a null InputStream a the first argument.");

	PKCS11LoadStoreParameter param = new PKCS11LoadStoreParameter();

	param.setProtectionParameter(new PasswordProtection(pin));

	engineLoad(param);
}
 
开发者ID:CardContact,项目名称:opensc-java,代码行数:14,代码来源:PKCS11KeyStoreSpi.java



注:本文中的java.security.KeyStore.PasswordProtection类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AsyncImageView类代码示例发布时间:2022-05-21
下一篇:
Java CopyPasteManager类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap