本文整理匯總了Java中javax.net.ssl.X509KeyManager.getPrivateKey方法的典型用法代碼示例。如果您正苦於以下問題:Java X509KeyManager.getPrivateKey方法的具體用法?Java X509KeyManager.getPrivateKey怎麽用?Java X509KeyManager.getPrivateKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.net.ssl.X509KeyManager
的用法示例。
在下文中一共展示了X509KeyManager.getPrivateKey方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCardProvider
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
@Test
@Ignore
public void testCardProvider() throws GeneralSecurityException, CardException {
DelegatingProvider cp = DelegatingProvider.fromDelegate(CardDelegate.any(false, CONSOLE));
Assume.assumeNotNull(cp);
Security.insertProviderAt(cp, 0);
X509KeyManager km = cp.getKeyManager();
String alias = km.chooseClientAlias(new String[]{"RSA"}, null, null);
PrivateKey pk = km.getPrivateKey(alias);
Signature s = Signature.getInstance("SHA256withRSA");
s.initSign(pk);
s.update(HexUtils.hex2bin("311fe3feed16b9cd8df0f8b1517be5cb86048707df4889ba8dc37d4d68866d02"));
byte[] result = s.sign();
System.out.println(HexUtils.bin2hex(result));
}
示例2: test_X509KeyManager_alias
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType) {
if (alias == null) {
assertNull(km.getCertificateChain(alias));
assertNull(km.getPrivateKey(alias));
return;
}
X509Certificate[] certificateChain = km.getCertificateChain(alias);
PrivateKey privateKey = km.getPrivateKey(alias);
if (keyType == null) {
keyType = privateKey.getAlgorithm();
} else {
assertEquals(keyType, certificateChain[0].getPublicKey().getAlgorithm());
assertEquals(keyType, privateKey.getAlgorithm());
}
PrivateKeyEntry privateKeyEntry
= TestKeyStore.privateKey(TEST_KEY_STORE.keyStore,
TEST_KEY_STORE.storePassword,
keyType);
assertEquals(Arrays.asList(privateKeyEntry.getCertificateChain()),
Arrays.asList(certificateChain));
assertEquals(privateKeyEntry.getPrivateKey(), privateKey);
}
示例3: getPrivateKey
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
@Override
public PrivateKey getPrivateKey(final String alias) {
for (final X509KeyManager keyManager : keyManagers) {
final PrivateKey privateKey = keyManager.getPrivateKey(alias);
if (privateKey != null) {
return privateKey;
}
}
return null;
}
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:11,代碼來源:FileTrustStoreSslSocketFactory.java
示例4: setCertificate
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
void setCertificate(String alias) throws CertificateEncodingException, SSLException {
if (alias == null) {
return;
}
X509KeyManager keyManager = parameters.getX509KeyManager();
if (keyManager == null) {
return;
}
PrivateKey privateKey = keyManager.getPrivateKey(alias);
if (privateKey == null) {
return;
}
localCertificates = keyManager.getCertificateChain(alias);
if (localCertificates == null) {
return;
}
int numLocalCerts = localCertificates.length;
PublicKey publicKey = (numLocalCerts > 0) ? localCertificates[0].getPublicKey() : null;
// Encode the local certificates.
byte[][] encodedLocalCerts = new byte[numLocalCerts][];
for (int i = 0; i < numLocalCerts; ++i) {
encodedLocalCerts[i] = localCertificates[i].getEncoded();
}
// Convert the key so we can access a native reference.
final OpenSSLKey key;
try {
key = OpenSSLKey.fromPrivateKeyForTLSStackOnly(privateKey, publicKey);
} catch (InvalidKeyException e) {
throw new SSLException(e);
}
// Set the local certs and private key.
NativeCrypto.setLocalCertsAndPrivateKey(ssl, encodedLocalCerts, key.getNativeRef());
}
示例5: test_X509KeyManager_alias
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
private void test_X509KeyManager_alias(X509KeyManager km, String alias, String keyType,
boolean many, boolean empty) throws Exception {
if (empty || (!many && (keyType == null || keyType.isEmpty()))) {
assertNull(keyType, alias);
assertNull(keyType, km.getCertificateChain(alias));
assertNull(keyType, km.getPrivateKey(alias));
return;
}
assertNotNull(keyType, alias);
X509Certificate[] certificateChain = km.getCertificateChain(alias);
PrivateKey privateKey = km.getPrivateKey(alias);
String keyAlgName = privateKey.getAlgorithm();
X509Certificate certificate = certificateChain[0];
assertEquals(keyType, keyAlgName, certificate.getPublicKey().getAlgorithm());
String sigAlgName = certificate.getSigAlgName();
PrivateKeyEntry privateKeyEntry = getTestKeyStore().getPrivateKey(keyAlgName, sigAlgName);
assertEquals(keyType, Arrays.asList(privateKeyEntry.getCertificateChain()),
Arrays.<Certificate>asList(certificateChain));
assertEquals(keyType, privateKeyEntry.getPrivateKey(), privateKey);
if (keyType != null) {
assertEquals(TestKeyStore.keyAlgorithm(keyType), keyAlgName);
// Skip this when we're given only "DH" or "EC" instead of "DH_DSA",
// "EC_RSA", etc. since we don't know what the expected
// algorithm was.
if (!keyType.equals("DH") && !keyType.equals("EC")) {
assertTrue(sigAlgName.contains(TestKeyStore.signatureAlgorithm(keyType)));
}
}
}
示例6: getPrivateKey
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
public synchronized PrivateKey getPrivateKey(String alias) {
String[] parts = alias.split(SEP, 2);
String description = parts[0];
alias = parts[1];
X509KeyManager km = _managers.get(description);
return km.getPrivateKey(alias);
}
示例7: getPrivateKey
import javax.net.ssl.X509KeyManager; //導入方法依賴的package包/類
/**
* Returns the first non-null private key associated with the given alias, or {@code null} if
* the alias can't be found.
*/
@Override
public @Nullable PrivateKey getPrivateKey(String alias){
for (List<X509KeyManager> keyManagers : keyManagers.values()) {
for (X509KeyManager x509KeyManager : keyManagers) {
PrivateKey privateKey = x509KeyManager.getPrivateKey(alias);
if (privateKey != null) {
return privateKey;
}
}
}
return null;
}