本文整理汇总了Java中java.security.KeyStore.PrivateKeyEntry.getPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:Java PrivateKeyEntry.getPrivateKey方法的具体用法?Java PrivateKeyEntry.getPrivateKey怎么用?Java PrivateKeyEntry.getPrivateKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.KeyStore.PrivateKeyEntry
的用法示例。
在下文中一共展示了PrivateKeyEntry.getPrivateKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: PatchBuilder
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public PatchBuilder(File outFile, File dexFile, PrivateKeyEntry key,
PrintStream verboseStream) {
try {
if (null != key) {
mBuilder = new SignedJarBuilder(
new FileOutputStream(outFile, false), key.getPrivateKey(),
(X509Certificate) key.getCertificate());
} else {
mBuilder = new SignedJarBuilder(
new FileOutputStream(outFile, false), null,
null);
}
mBuilder.writeFile(dexFile, "classes.dex");
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: entry2Pair
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
private static KeyPair entry2Pair(Entry entry) {
PublicKey pub = null;
PrivateKey priv = null;
if (entry instanceof PrivateKeyEntry) {
PrivateKeyEntry pk = (PrivateKeyEntry) entry;
if (pk.getCertificate() != null) {
pub = pk.getCertificate().getPublicKey();
}
priv = pk.getPrivateKey();
} else if (entry instanceof TrustedCertificateEntry) {
TrustedCertificateEntry tc = (TrustedCertificateEntry) entry;
pub = tc.getTrustedCertificate().getPublicKey();
} else {
throw new IllegalArgumentException(
"Only entry types PrivateKeyEntry and TrustedCertificateEntry are supported.");
}
return new KeyPair(pub, priv);
}
示例3: setKeystore
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public JettyKeystoreConvertorBuilder setKeystore(InputStream inputStream, String password, String alias, String type) throws JettyKeystoreException {
KeyStore keystore = loadKeyStore(inputStream, password, type);
try {
PrivateKeyEntry privateKeyEntry = getPrivateKeyEntryOfKeyStore(keystore, password, alias);
privateKey = privateKeyEntry.getPrivateKey();
certificate = privateKeyEntry.getCertificate();
} catch (JettyKeystoreException e) {
throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_KEYSTORE, "Can not load file (Keystore)", e);
}
return this;
}
示例4: testPKCS1viaPKCS11
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的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)
}
示例5: setPrivateKeyFromKeystore
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
public JettyKeystoreConvertorBuilder setPrivateKeyFromKeystore(InputStream inputStream, String password, String alias, String type) throws JettyKeystoreException {
KeyStore keystore = loadKeyStore(inputStream, password, type);
try {
PrivateKeyEntry privateKeyEntry = getPrivateKeyEntryOfKeyStore(keystore, password, alias);
privateKey = privateKeyEntry.getPrivateKey();
} catch (JettyKeystoreException e) {
throw new JettyKeystoreException(JettyKeystoreException.ERROR_LOAD_KEYSTORE, "Can not load file (Keystore)", e);
}
return this;
}
示例6: signSamlAssertion
import java.security.KeyStore.PrivateKeyEntry; //导入方法依赖的package包/类
/**
* Signs and returns the w3c representation of the document containing the SAML assertion.
*
* @param document
* w3c document to be signed.
* @return w3c representation of the signed document.
* @throws TransformerException
* @throws NoSuchAlgorithmException
* @throws InvalidAlgorithmParameterException
* @throws KeyException
* @throws MarshalException
* @throws XMLSignatureException
*/
public Document signSamlAssertion(Document document) throws TransformerException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException, KeyException, MarshalException, XMLSignatureException {
if (document != null) {
PrivateKeyEntry entry = getPrivateKeyEntryFromKeystore();
PrivateKey privateKey = entry.getPrivateKey();
X509Certificate certificate = (X509Certificate) entry.getCertificate();
Element signedElement = signSamlAssertion(document, privateKey, certificate);
return signedElement.getOwnerDocument();
}
return null;
}