List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:com.buession.mcrypt.Mcrypt.java
/** * /*from w w w.j a v a 2s . co m*/ * * @param object * ? * @return ? */ public String encode(final Object object) { if (object == null) { throw new IllegalArgumentException("String could not be null"); } if (algo == null || algo.length() == 0) { throw new RuntimeException("Algo could not be null"); } try { MessageDigest messageDigest = provider == null ? MessageDigest.getInstance(algo) : MessageDigest.getInstance(algo, provider); if (object instanceof char[]) { return encode(new String((char[]) object), messageDigest); } else if (object instanceof byte[]) { return encode(new String((byte[]) object, characterEncoding), messageDigest); } else { return encode(object.toString(), messageDigest); } } catch (final NoSuchAlgorithmException e) { logger.error(e.getMessage()); throw new SecurityException(e); } catch (UnsupportedEncodingException e) { logger.error(e.getMessage()); } return null; }
From source file:org.hyperic.util.security.DatabaseSSLProviderImpl.java
private TrustManagerFactory getTrustManagerFactory(final KeyStore keystore) throws KeyStoreException, IOException { try {//from ww w . j a v a 2s . c o m TrustManagerFactory trustManagerFactory = TrustManagerFactory .getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(keystore); return trustManagerFactory; } catch (NoSuchAlgorithmException e) { // no support for algorithm, if this happens we're kind of screwed // we're using the default so it should never happen log.error("The algorithm is not supported. Error message:" + e.getMessage()); throw new KeyStoreException(e); } }
From source file:org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory.java
private SSLContext createSSLContext() { try {//from ww w . j a v a 2 s . co m KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; if (this.keystoreUrl != null) { KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword); if (LOG.isDebugEnabled()) { Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { LOG.debug("Certificate chain '" + alias + "':"); for (int c = 0; c < certs.length; c++) { if (certs[c] instanceof X509Certificate) { X509Certificate cert = (X509Certificate) certs[c]; LOG.debug(" Certificate " + (c + 1) + ":"); LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } } } keymanagers = createKeyManagers(keystore, this.keystorePassword); } if (this.truststoreUrl != null) { KeyStore keystore = createKeyStore(this.truststoreUrl, this.truststorePassword); if (LOG.isDebugEnabled()) { Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = aliases.nextElement(); LOG.debug("Trusted certificate '" + alias + "':"); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert != null && trustedcert instanceof X509Certificate) { X509Certificate cert = (X509Certificate) trustedcert; LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } trustmanagers = createTrustManagers(keystore); } SSLContext sslcontext = SSLContext.getInstance("SSLv3"); sslcontext.init(keymanagers, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationException("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationException("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationException("Key management exception: " + e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationException( "I/O error reading keystore/truststore file: " + e.getMessage()); } }
From source file:br.gov.serpro.cert.AuthSSLProtocolSocketFactory.java
private SSLContext createSSLContext() { try {/*ww w . j a v a2 s . c om*/ // KeyManager[] keymanagers = null; TrustManager[] trustmanagers = null; /* if (this.keystoreUrl != null) { KeyStore keystore = createKeyStore(this.keystoreUrl, this.keystorePassword); if (LOG.isDebugEnabled()) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String)aliases.nextElement(); Certificate[] certs = keystore.getCertificateChain(alias); if (certs != null) { LOG.debug("Certificate chain '" + alias + "':"); for (int c = 0; c < certs.length; c++) { if (certs[c] instanceof X509Certificate) { X509Certificate cert = (X509Certificate)certs[c]; LOG.debug(" Certificate " + (c + 1) + ":"); LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore() ); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } } } keymanagers = createKeyManagers(keystore, this.keystorePassword); } */ if (this.truststoreUrls != null) { KeyStore keystore = createKeyStore(this.truststoreUrls, this.truststorePasswords); if (LOG.isDebugEnabled()) { Enumeration aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); LOG.debug("Trusted certificate '" + alias + "':"); Certificate trustedcert = keystore.getCertificate(alias); if (trustedcert != null && trustedcert instanceof X509Certificate) { X509Certificate cert = (X509Certificate) trustedcert; LOG.debug(" Subject DN: " + cert.getSubjectDN()); LOG.debug(" Signature Algorithm: " + cert.getSigAlgName()); LOG.debug(" Valid from: " + cert.getNotBefore()); LOG.debug(" Valid until: " + cert.getNotAfter()); LOG.debug(" Issuer: " + cert.getIssuerDN()); } } } trustmanagers = createTrustManagers(keystore); } SSLContext sslcontext = SSLContext.getInstance("SSL"); sslcontext.init(null, trustmanagers, null); return sslcontext; } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationError("Unsupported algorithm exception: " + e.getMessage()); } catch (KeyStoreException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationError("Keystore exception: " + e.getMessage()); } catch (GeneralSecurityException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationError("Key management exception: " + e.getMessage()); } catch (IOException e) { LOG.error(e.getMessage(), e); throw new AuthSSLInitializationError("I/O error reading keystore/truststore file: " + e.getMessage()); } }
From source file:io.kodokojo.bdd.stage.cluster.ClusterApplicationGiven.java
private void startRedis() { redisService = StageUtils.startDockerRedis(dockerTestSupport); KeyGenerator kg = null;/*from w w w .ja va2 s.c om*/ try { kg = KeyGenerator.getInstance("AES"); userStore = new RedisUserStore(kg.generateKey(), redisService.getHost(), redisService.getPort()); } catch (NoSuchAlgorithmException e) { fail(e.getMessage()); } }
From source file:org.wso2.carbon.apimgt.gateway.handlers.security.basicauth.BasicAuthCredentialValidator.java
/** * Returns the md5 hash of a given string. * * @param str the string input to be hashed * @return hashed string/* ww w .j a va2s . co m*/ */ private String hashString(String str) { String generatedHash = null; try { // Create MessageDigest instance for MD5 MessageDigest md = MessageDigest.getInstance("MD5"); //Add str bytes to digest md.update(str.getBytes()); //Get the hash's bytes byte[] bytes = md.digest(); //This bytes[] has bytes in decimal format; //Convert it to hexadecimal format StringBuilder sb = new StringBuilder(); for (byte aByte : bytes) { sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1)); } //Get complete hashed str in hex format generatedHash = sb.toString(); } catch (NoSuchAlgorithmException e) { log.error(e.getMessage()); } return generatedHash; }
From source file:org.bitrepository.commandline.CommandLineClient.java
/** * Create the ChecksumSpecTYPE based on the cmd-line arguments. * Do not use directly. Use either 'getRequestChecksumSpecOrNull' or 'getRequestChecksumSpecOrDefault' to handle * the case, when no request arguments have been defined. * @return The requested checksum spec.//from ww w .j a v a 2 s . c om */ private ChecksumSpecTYPE getRequestChecksumSpec() { ChecksumSpecTYPE res = new ChecksumSpecTYPE(); res.setChecksumType(ChecksumType.fromValue(cmdHandler.getOptionValue(Constants.REQUEST_CHECKSUM_TYPE_ARG))); if (cmdHandler.hasOption(Constants.REQUEST_CHECKSUM_SALT_ARG)) { res.setChecksumSalt( Base16Utils.encodeBase16(cmdHandler.getOptionValue(Constants.REQUEST_CHECKSUM_SALT_ARG))); } try { ChecksumUtils.verifyAlgorithm(res); } catch (NoSuchAlgorithmException e) { output.error("Invalid checksum algorithm: " + e.getMessage()); throw new IllegalStateException("Invalid checksumspec for '" + res + "'", e); } return res; }
From source file:org.openadaptor.util.hosting.HostedConnection.java
protected HostedConnection() { log.debug("Installing all-trusting Security manager"); SSLContext sc;//from ww w .j a va 2s. c o m try { sc = SSLContext.getInstance("SSL"); sc.init(null, trustManagers, new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); new URL("https://not.real"); } catch (NoSuchAlgorithmException e) { fail("Failed to establish SSL context", e); } catch (KeyManagementException e) { fail(e.getMessage(), e); } catch (MalformedURLException e) { fail("Failed to setup security manager " + e); } }
From source file:org.hyperic.util.security.DatabaseSSLProviderImpl.java
private KeyManagerFactory getKeyManagerFactory(final KeyStore keystore, final String password) throws KeyStoreException { try {/*from w ww. j a va 2 s . c o m*/ KeyManagerFactory keyManagerFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyManagerFactory.init(keystore, password.toCharArray()); return keyManagerFactory; } catch (NoSuchAlgorithmException e) { // no support for algorithm, if this happens we're kind of screwed // we're using the default so it should never happen throw new KeyStoreException("The algorithm is not supported. Error message:" + e.getMessage()); } catch (UnrecoverableKeyException e) { // invalid password, should never happen throw new KeyStoreException("Password for the keystore is invalid. Error message:" + e.getMessage()); } }
From source file:Jigs_Desktop_Client.GUI.FXMLDocumentController.java
@FXML private void authenticateUser(ActionEvent event) { from_user = this.user_name.getText(); String pass_txt = this.password.getText(); try {//from w w w.j av a 2 s. c o m MessageDigest m = MessageDigest.getInstance("MD5"); m.update(pass_txt.getBytes(), 0, pass_txt.length()); pass_txt = (new BigInteger(1, m.digest()).toString(16)); } catch (NoSuchAlgorithmException e) { this.login_status.setText(e.getMessage()); this.alert("resources/app_error.mp3"); return; } if ((from_user.equals("")) || (pass_txt.equals(""))) { this.login_status.setText("Username or password can't left empty!"); this.alert("resources/app_error.mp3"); return; } if (jc.authenticateUser(from_user, pass_txt)) { this.alert("resources/app_login.mp3"); this.login_status.setText("Logged In as: @" + from_user); this.my_circle_tab.setDisable(false); message_tab.setDisable(false); this.btn_logout.setDisable(false); this.user_name.setDisable(true); this.password.setDisable(true); this.btn_login.setDisable(true); main_tab_pane.getSelectionModel().select(1); this.getMyCirclesList(); SyncMessages sm = new SyncMessages(this.from_user, "132.148.65.148", this); syncmessageThread = new Thread(sm); syncmessageThread.start(); SyncUserStatus sus = new SyncUserStatus("132.148.65.148", this); syncUserStatusThread = new Thread(sus); syncUserStatusThread.start(); this.messages.clear(); this.btn_login.setDefaultButton(false); this.btn_logout.setDefaultButton(true); this.jc.setStatus(from_user, "online"); this.btn_disconnect.setDisable(true); } else { this.login_status.setText("Error logging as @" + from_user); this.alert("resources/app_error.mp3"); } }