本文整理汇总了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;
}
});
}
示例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;
}
示例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)
}