List of usage examples for java.security GeneralSecurityException getMessage
public String getMessage()
From source file:jef.tools.security.EncrypterUtil.java
/** * ??DESKey//from w ww. ja v a 2 s . c o m * * @param password * @return */ public static final SecretKey toDESKey(String password) { byte[] bb = password.getBytes(); Assert.isTrue(bb.length > 7, "the secretKey for DES must be 8 bytes at least."); try { KeySpec keySpec = new DESKeySpec(bb); SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(keySpec); return key; } catch (GeneralSecurityException e) { throw new RuntimeException(e.getMessage()); } }
From source file:jef.tools.security.EncrypterUtil.java
/** * ??3DESKey/*w w w .j a v a 2 s .c o m*/ * * @param password * @return */ public static final SecretKey toDESedeKey(String password) { byte[] bb = password.getBytes(); Assert.isTrue(bb.length > 23, "the secretKey for 3DES must be 24 bytes at least."); try { KeySpec keySpec = new DESedeKeySpec(bb); SecretKey key = SecretKeyFactory.getInstance("DESede").generateSecret(keySpec); return key; } catch (GeneralSecurityException e) { throw new RuntimeException(e.getMessage()); } }
From source file:uk.ac.cam.cl.dtg.segue.api.managers.UserAuthenticationManager.java
/** * Generate an HMAC using a key and the data to sign. * /* ww w.j ava2s .c om*/ * @param key * - HMAC key for signing * @param dataToSign * - data to be signed * @return HMAC - Unique HMAC. */ public static String calculateHMAC(final String key, final String dataToSign) { Validate.notEmpty(key, "Signing key cannot be blank."); Validate.notEmpty(dataToSign, "Data to sign cannot be blank."); try { SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), HMAC_SHA_ALGORITHM); Mac mac = Mac.getInstance(HMAC_SHA_ALGORITHM); mac.init(signingKey); byte[] rawHmac = mac.doFinal(dataToSign.getBytes()); String result = new String(Base64.encodeBase64(rawHmac)); return result; } catch (GeneralSecurityException e) { log.warn("Unexpected error while creating hash: " + e.getMessage(), e); throw new IllegalArgumentException(); } }
From source file:net.java.sip.communicator.service.httputil.HttpUtils.java
/** * Returns the preconfigured http client, * using CertificateVerificationService, timeouts, user-agent, * hostname verifier, proxy settings are used from global java settings, * if protected site is hit asks for credentials * using util.swing.AuthenticationWindow. * @param usernamePropertyName the property to use to retrieve/store * username value if protected site is hit, for username * ConfigurationService service is used. * @param passwordPropertyName the property to use to retrieve/store * password value if protected site is hit, for password * CredentialsStorageService service is used. * @param credentialsProvider if not null provider will bre reused * in the new client//from w w w . j av a2 s . c o m * @param address the address we will be connecting to */ public static DefaultHttpClient getHttpClient(String usernamePropertyName, String passwordPropertyName, final String address, CredentialsProvider credentialsProvider) throws IOException { HttpParams params = new BasicHttpParams(); params.setParameter(CoreConnectionPNames.SO_TIMEOUT, 10000); params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); params.setParameter(ClientPNames.MAX_REDIRECTS, MAX_REDIRECTS); DefaultHttpClient httpClient = new DefaultHttpClient(params); HttpProtocolParams.setUserAgent(httpClient.getParams(), System.getProperty("sip-communicator.application.name") + "/" + System.getProperty("sip-communicator.version")); SSLContext sslCtx; try { sslCtx = HttpUtilActivator.getCertificateVerificationService() .getSSLContext(HttpUtilActivator.getCertificateVerificationService().getTrustManager(address)); } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } // note to any reviewer concerned about ALLOW_ALL_HOSTNAME_VERIFIER: // the SSL context obtained from the certificate service takes care of // certificate validation try { Scheme sch = new Scheme("https", 443, new SSLSocketFactoryEx(sslCtx)); httpClient.getConnectionManager().getSchemeRegistry().register(sch); } catch (Throwable t) { logger.error("Error creating ssl socket factory", t); } // set proxy from default jre settings ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); if (credentialsProvider == null) credentialsProvider = new HTTPCredentialsProvider(usernamePropertyName, passwordPropertyName); httpClient.setCredentialsProvider(credentialsProvider); // enable retry connecting with default retry handler // when connecting has prompted for authentication // connection can be disconnected nefore user answers and // we need to retry connection, using the credentials provided httpClient.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true)); return httpClient; }
From source file:org.kuali.rice.core.framework.persistence.ojb.conversion.OjbKualiHashFieldConversion.java
/** * @see FieldConversion#javaToSql(Object) *//* w w w. j a v a2s . c o m*/ public Object javaToSql(Object source) { Object converted = source; if (converted != null) { // don't convert if already a hashed value if (converted.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { converted = StringUtils.stripEnd(converted.toString(), EncryptionService.HASH_POST_PREFIX); } else { try { converted = CoreApiServiceLocator.getEncryptionService().hash(converted); } catch (GeneralSecurityException e) { throw new RuntimeException("Unable to hash value to db: " + e.getMessage()); } } } return converted; }
From source file:com.intel.cryptostream.JceAesCtrCryptoCodec.java
public JceAesCtrCryptoCodec() { provider = CryptoStreamUtils.getJCEProvider(); final String secureRandomAlg = CryptoStreamUtils.getSecureRandomAlg(); try {/*from www .j a v a 2s.c o m*/ random = (provider != null) ? SecureRandom.getInstance(secureRandomAlg, provider) : SecureRandom.getInstance(secureRandomAlg); } catch (GeneralSecurityException e) { LOG.warn(e.getMessage()); random = new SecureRandom(); } }
From source file:com.intel.chimera.codec.JceAesCtrCryptoCodec.java
public JceAesCtrCryptoCodec(Properties props) { provider = Utils.getJCEProvider(props); final String secureRandomAlg = Utils.getSecureRandomAlg(props); try {//from w w w. j av a2 s .c om random = (provider != null) ? SecureRandom.getInstance(secureRandomAlg, provider) : SecureRandom.getInstance(secureRandomAlg); } catch (GeneralSecurityException e) { LOG.warn(e.getMessage()); random = new SecureRandom(); } }
From source file:org.rhq.enterprise.server.plugins.rhnhosted.xmlrpc.RhnSSLTransport.java
@Override protected URLConnection newURLConnection(URL url) throws IOException { URLConnection c = super.newURLConnection(url); if (c instanceof HttpsURLConnection) { try {//from ww w . j a va2s . c o m ((HttpsURLConnection) c).setSSLSocketFactory(RHNSSLSocketFactory.getSSLSocketFactory(sslCertPath)); } catch (GeneralSecurityException e) { e.printStackTrace(); log.error(e); throw new IOException(e.getMessage()); } log.debug("SSLSocketFactory has been set with a custom version using cert path: " + sslCertPath); } return c; }
From source file:org.apache.hadoop.crypto.JceAesCtrCryptoCodec.java
@Override public void setConf(Configuration conf) { this.conf = conf; provider = conf.get(HADOOP_SECURITY_CRYPTO_JCE_PROVIDER_KEY); final String secureRandomAlg = conf.get(HADOOP_SECURITY_JAVA_SECURE_RANDOM_ALGORITHM_KEY, HADOOP_SECURITY_JAVA_SECURE_RANDOM_ALGORITHM_DEFAULT); try {//from w ww. ja va 2s. c o m random = (provider != null) ? SecureRandom.getInstance(secureRandomAlg, provider) : SecureRandom.getInstance(secureRandomAlg); } catch (GeneralSecurityException e) { LOG.warn(e.getMessage()); random = new SecureRandom(); } }
From source file:org.kuali.rice.core.framework.persistence.jpa.type.HibernateKualiHashType.java
/** * sets the hash value on the PreparedStatement * // w w w. j a v a 2s. c o m * @see org.hibernate.usertype.UserType#nullSafeSet(java.sql.PreparedStatement, java.lang.Object, int) */ public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException { Object converted = value; if (converted != null) { // don't convert if already a hashed value if (converted.toString().endsWith(EncryptionService.HASH_POST_PREFIX)) { converted = StringUtils.stripEnd(converted.toString(), EncryptionService.HASH_POST_PREFIX); } else { try { converted = CoreApiServiceLocator.getEncryptionService().hash(converted); } catch (GeneralSecurityException e) { throw new RuntimeException("Unable to hash value to db: " + e.getMessage()); } } } if (converted == null) { st.setNull(index, Types.VARCHAR); } else { st.setString(index, (String) converted); } }