List of usage examples for java.security KeyStore getCertificateChain
public final Certificate[] getCertificateChain(String alias) throws KeyStoreException
From source file:test.integ.be.fedict.trust.BelgianIdentityCardTrustValidatorTest.java
@Test public void testValidateSignatureCertificate() throws Exception { Security.addProvider(new BeIDProvider()); KeyStore keyStore = KeyStore.getInstance("BeID"); keyStore.load(null);/*from w w w .ja va 2 s.com*/ Certificate[] certificateChain = keyStore.getCertificateChain("Signature"); LOG.debug("certificate: " + certificateChain[0]); Security.addProvider(new BouncyCastleProvider()); CertificateRepository certificateRepository = BelgianTrustValidatorFactory.createCertificateRepository(); TrustValidator trustValidator = new TrustValidator(certificateRepository); TrustValidatorDecorator trustValidatorDecorator = new TrustValidatorDecorator(); trustValidatorDecorator.addDefaultTrustLinkerConfig(trustValidator); trustValidator.addCertificateConstrain(new QCStatementsCertificateConstraint(true, true)); trustValidator.isTrusted(certificateChain); }
From source file:test.integ.be.fedict.trust.BelgianIdentityCardTrustValidatorTest.java
@Test public void testValidity() throws Exception { Security.addProvider(new BeIDProvider()); KeyStore keyStore = KeyStore.getInstance("BeID"); keyStore.load(null);//from w ww .j a v a 2 s. com Certificate[] authnCertificateChain = keyStore.getCertificateChain("Authentication"); LOG.debug("authn cert: " + authnCertificateChain[0]); Security.addProvider(new BouncyCastleProvider()); NetworkConfig networkConfig = null; // new NetworkConfig("proxy.yourict.net", 8080); CertificateRepository certificateRepository = BelgianTrustValidatorFactory.createCertificateRepository(); TrustValidator trustValidator = new TrustValidator(certificateRepository); trustValidator.addTrustLinker(new PublicKeyTrustLinker()); // OverrideOnlineOcspRepository ocspRepository = new // OverrideOnlineOcspRepository( // networkConfig); OnlineOcspRepository ocspRepository = new OnlineOcspRepository(networkConfig); // ocspRepository.overrideOCSP(new URI("http://ocsp.eid.belgium.be"), // new URI("http://64.18.17.111")); OnlineCrlRepository crlRepository = new OnlineCrlRepository(networkConfig); CachedCrlRepository cachedCrlRepository = new CachedCrlRepository(crlRepository); trustValidator.addTrustLinker(new OcspTrustLinker(ocspRepository)); trustValidator.addTrustLinker(new CrlTrustLinker(cachedCrlRepository)); trustValidator.isTrusted(authnCertificateChain); }
From source file:org.wso2.carbon.core.util.CryptoUtil.java
/** * Encrypt a given plain text//from w w w .j a va 2 s . com * * @param plainTextBytes The plaintext bytes to be encrypted * @return The cipher text bytes * @throws CryptoException On error during encryption */ public byte[] encrypt(byte[] plainTextBytes) throws CryptoException { try { KeyStoreManager keyMan = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID, this.getServerConfigService(), this.getRegistryService()); KeyStore keyStore = keyMan.getPrimaryKeyStore(); Certificate[] certs = keyStore.getCertificateChain(keyAlias); Cipher cipher = Cipher.getInstance("RSA", "BC"); cipher.init(Cipher.ENCRYPT_MODE, certs[0].getPublicKey()); return cipher.doFinal(plainTextBytes); } catch (Exception e) { e.printStackTrace(); throw new CryptoException(Messages.getMessage("erorDuringEncryption"), e); } }
From source file:net.sf.keystore_explorer.gui.actions.ExportKeyPairPublicKeyAction.java
private X509Certificate[] getCertificateChain(String alias) throws CryptoException { try {/*from www. j ava 2 s . c om*/ KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory(); KeyStore keyStore = history.getCurrentState().getKeyStore(); X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)); return certChain; } catch (KeyStoreException ex) { String message = MessageFormat .format(res.getString("ExportKeyPairPublicKeyAction.NoAccessEntry.message"), alias); throw new CryptoException(message, ex); } }
From source file:com.thoughtworks.go.security.KeyStoreManager.java
public boolean hasCertificates(String friendlyName, File storeFile, String passwd) { try {//from ww w. j a va 2 s . c o m KeyStore keyStore = loadOrEmpty(storeFile, passwd); bombIfNull(keyStore, "Store not yet initialized"); return keyStore.getCertificateChain(friendlyName) != null; } catch (Exception e) { return false; } }
From source file:net.sf.keystore_explorer.gui.actions.ExportKeyPairCertificateChainAction.java
private X509Certificate[] getCertificateChain(String alias) throws CryptoException { try {/* ww w . jav a2 s .com*/ KeyStoreHistory history = kseFrame.getActiveKeyStoreHistory(); KeyStore keyStore = history.getCurrentState().getKeyStore(); X509Certificate[] certChain = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias)); return certChain; } catch (KeyStoreException ex) { String message = MessageFormat .format(res.getString("ExportKeyPairCertificateChainAction.NoAccessEntry.message"), alias); throw new CryptoException(message, ex); } }
From source file:com.vmware.identity.idm.server.ClientCertTestUtils.java
public Certificate[] getTenantCredentialCert(String certAlias) throws Exception { Properties props = getTestProperties(); KeyStore ks = loadKeyStore(props.getProperty(STS_STORE_JKS), props.getProperty(STS_STORE_PASS)); return ks.getCertificateChain(certAlias); }
From source file:com.vmware.identity.idm.server.ClientCertTestUtils.java
/** * @return "Certificate.Valid.9000080970" chain including intermediate CA and root CA * @throws KeyStoreException/* ww w .j a v a 2s . co m*/ */ public Certificate[] getDoDValidCertChain() throws KeyStoreException { KeyStore ks = loadKeyStoreWithType(this.dodValidStore, this.dodStorePass, "PKCS12"); Certificate[] certs = ks.getCertificateChain(this.dodValidCertAlias); return certs; }
From source file:com.vmware.identity.idm.server.ClientCertTestUtils.java
/** * @return "Certificate.Revoked.9000080969" chain including intermediate CA and root CA * @throws KeyStoreException/* ww w .ja v a2 s . c o m*/ */ public Certificate[] getDoDRevokedCert() throws KeyStoreException { KeyStore ks = loadKeyStoreWithType(this.dodRevokedStore, this.dodStorePass, "PKCS12"); Certificate[] certs = ks.getCertificateChain(this.dodRevokedCertAlias); return certs; }
From source file:com.vmware.identity.idm.server.ClientCertTestUtils.java
public Certificate[] getTenantCredentialCustomCert(String certAlias) throws Exception { Properties props = getTestProperties(); KeyStore ks = loadKeyStore(props.getProperty(CUSTOM_STORE_JKS), props.getProperty(CUSTOM_STORE_PASS)); return ks.getCertificateChain(certAlias); }