List of usage examples for java.security KeyStoreException toString
public String toString()
From source file:de.niklasmerz.cordova.fingerprint.Fingerprint.java
private static SecretKey getSecretKey() { String errorMessage = ""; String getSecretKeyExceptionErrorPrefix = "Failed to get SecretKey from KeyStore: "; SecretKey key = null;//from w w w. j ava2 s .com try { mKeyStore.load(null); key = (SecretKey) mKeyStore.getKey(mClientId, null); } catch (KeyStoreException e) { errorMessage = getSecretKeyExceptionErrorPrefix + "KeyStoreException: " + e.toString(); ; } catch (CertificateException e) { errorMessage = getSecretKeyExceptionErrorPrefix + "CertificateException: " + e.toString(); ; } catch (UnrecoverableKeyException e) { errorMessage = getSecretKeyExceptionErrorPrefix + "UnrecoverableKeyException: " + e.toString(); ; } catch (IOException e) { errorMessage = getSecretKeyExceptionErrorPrefix + "IOException: " + e.toString(); ; } catch (NoSuchAlgorithmException e) { errorMessage = getSecretKeyExceptionErrorPrefix + "NoSuchAlgorithmException: " + e.toString(); ; } if (key == null) { Log.e(TAG, errorMessage); } return key; }
From source file:com.jonbanjo.cupsprint.CertificateActivity.java
private void displayCert(final String alias) { X509Certificate cert;//from w w w. j a va2 s . co m try { cert = (X509Certificate) trustStore.getCertificate(alias); } catch (KeyStoreException e) { showToast(e.toString()); return; } String certString = cert.toString(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Certificate").setMessage(certString) .setPositiveButton("Remove", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { removeCert(alias); } }).setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog dialog = builder.create(); dialog.show(); }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public void addPublicKey(KeyStore ks, KeyPair keyPair, String keyPairName, String keyPairSubjectDN) throws CryptoException { try {/*from w w w . j ava 2 s. com*/ X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN); ks.setCertificateEntry(keyPairName, cert); } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
/** * * @param ks/* www.j ava 2 s .c o m*/ * @param keyPair * @param keyPairName * @param keyPairSubjectDN * @param before * @param expiry * @throws CryptoException */ public void addPublicKey(KeyStore ks, KeyPair keyPair, String keyPairName, String keyPairSubjectDN, Calendar before, Calendar expiry) throws CryptoException { try { X509Certificate cert = generateV3Certificate(keyPair, keyPairSubjectDN, before, expiry); ks.setCertificateEntry(keyPairName, cert); } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public byte[] convertKeystoreByteArray(KeyStore keyStore, String keyStorePassphrase) throws CryptoException { byte[] keyStoreBytes; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try {/*from w ww. j a v a2s.co m*/ keyStore.store(outputStream, keyStorePassphrase.toCharArray()); keyStoreBytes = outputStream.toByteArray(); return keyStoreBytes; } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (NoSuchAlgorithmException e) { this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (CertificateException e) { this.logger.error("CertificateException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (IOException e) { this.logger.error("IOException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } finally { try { outputStream.close(); } catch (IOException e) { this.logger.error("IOException thrown in finally, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); } } }
From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java
public KeyStore generateKeyStore() throws CryptoException { try {/* w ww . j a va 2 s. c om*/ logger.debug("Generating a new key store."); /* Add BC to the jdk security manager to be able to use it as a provider */ Security.addProvider(new BouncyCastleProvider()); /* Create and init an empty key store */ KeyStore keyStore = KeyStore.getInstance("JKS"); keyStore.load(null, null); /* * Populate all new key stores with the key data of the local resolver, generally this is for metadata * purposes to ensure that all systems in the authentication network can correctly validate the signed * metadata document */ X509Certificate localCertificate = (X509Certificate) localResolver.getLocalCertificate(); Calendar before = new GregorianCalendar(); Calendar expiry = new GregorianCalendar(); before.setTime(localCertificate.getNotBefore()); expiry.setTime(localCertificate.getNotAfter()); addPublicKey(keyStore, new KeyPair(this.localResolver.getLocalPublicKey(), this.localResolver.getLocalPrivateKey()), this.localResolver.getLocalKeyAlias(), this.certIssuerDN, before, expiry); return keyStore; } catch (KeyStoreException e) { this.logger.error("KeyStoreException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (NoSuchAlgorithmException e) { this.logger.error("NoSuchAlgorithmException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (CertificateException e) { this.logger.error("CertificateException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } catch (IOException e) { this.logger.error("IOException thrown, " + e.getLocalizedMessage()); this.logger.debug(e.toString()); throw new CryptoException(e.getLocalizedMessage(), e); } }
From source file:org.glite.wms.wmproxy.WMProxyAPI.java
/** * Method that serves the constructors of the class * //from w w w. ja v a2 s .c o m * @param url * WMProxy service URL * @param proxyFile * the proxy in input as a stream * @param logPropFille * the path location of the log4j properties file * @throws ServiceException * If any error in calling the service * @throws CredentialException * in case of any error with the user proxy file * @throws ServiceURLException * malformed service URL specified as input */ private void WMProxyAPIConstructor(String url, String proxyFile, String certsPath) throws ServiceException, ServiceURLException { logger.debug("INPUT: url=[" + url + "] - proxyFile = [" + proxyFile + "] - certsPath=[" + certsPath + "]"); try { this.serviceURL = new URL(url); } catch (java.net.MalformedURLException exc) { throw new ServiceURLException(exc.getMessage()); } try { char[] emptyPwd = null; this.pemCredential = new PEMCredential(proxyFile, emptyPwd); } catch (KeyStoreException e) { logger.error("Failed retrieving proxy:" + e.toString()); } catch (CertificateException e) { logger.error("Failed retrieving proxy:" + e.toString()); } catch (IOException e) { logger.error("Failed reading proxy:" + e.toString()); } this.certsPath = certsPath; try { setSSLProperties(proxyFile); this.serviceStub = new WMProxyStub(serviceURL.toString()); this.grstStub = new org.gridsite.www.namespaces.delegation_2.WMProxyStub(serviceURL.toString()); } catch (AxisFault fault) { throw new ServiceException(fault.getMessage()); } }