当前位置: 首页>>代码示例>>Java>>正文


Java SunPKCS11类代码示例

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


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

示例1: go

import sun.security.pkcs11.SunPKCS11; //导入依赖的package包/类
public static void go(final String config) throws Exception {
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            SunPKCS11 provider = new SunPKCS11(config);
            Security.addProvider(provider);
            return null;
        }
    });
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:10,代码来源:ProviderLoader.java

示例2: initializeProviders

import sun.security.pkcs11.SunPKCS11; //导入依赖的package包/类
private String initializeProviders() {
	String providerName = null;
	BouncyCastleProvider providerBC = new BouncyCastleProvider();
	Security.addProvider(providerBC);
	
	byte[] decodedConfigurationFile = Base64.decodeBase64(tokenConfigurationBase64String);
	InputStream is = new ByteArrayInputStream(decodedConfigurationFile);
	Provider providerPKCS11 = new SunPKCS11(is);
	Security.addProvider(providerPKCS11);
	
	providerName =  providerPKCS11.getName();
	return providerName;
}
 
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:14,代码来源:CertificateProcessor.java

示例3: testPKCS1viaPKCS11

import sun.security.pkcs11.SunPKCS11; //导入依赖的package包/类
@Test
public void testPKCS1viaPKCS11() throws Exception {
	File tmpConfigFile = File.createTempFile("pkcs11-", "conf");
	tmpConfigFile.deleteOnExit();
	PrintWriter configWriter = new PrintWriter(new FileOutputStream(tmpConfigFile), true);
	configWriter.println("name=SmartCard");
	configWriter.println("library=/usr/lib/libbeidpkcs11.so.0");
	configWriter.println("slotListIndex=2");

	SunPKCS11 provider = new SunPKCS11(tmpConfigFile.getAbsolutePath());
	Security.addProvider(provider);
	KeyStore keyStore = KeyStore.getInstance("PKCS11", provider);
	keyStore.load(null, null);
	PrivateKeyEntry privateKeyEntry = (PrivateKeyEntry) keyStore.getEntry("Authentication", null);
	PrivateKey privateKey = privateKeyEntry.getPrivateKey();
	Signature signature = Signature.getInstance("SHA1withRSA");
	signature.initSign(privateKey);
	byte[] toBeSigned = "hello world".getBytes();
	signature.update(toBeSigned);
	byte[] signatureValue = signature.sign();

	X509Certificate certificate = (X509Certificate) privateKeyEntry.getCertificate();
	RSAPublicKey publicKey = (RSAPublicKey) certificate.getPublicKey();
	BigInteger signatureValueBigInteger = new BigInteger(signatureValue);
	BigInteger messageBigInteger = signatureValueBigInteger.modPow(publicKey.getPublicExponent(),
			publicKey.getModulus());
	LOG.debug("original message: " + new String(Hex.encodeHex(messageBigInteger.toByteArray())));

	// LOG.debug("ASN.1 signature: " + ASN1Dump.dumpAsString(obj)
}
 
开发者ID:e-Contract,项目名称:eid-applet,代码行数:31,代码来源:PKCS11Test.java


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