List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:com.core.util.wx.PayUtils.java
/** * ???// w ww . ja va2 s .c o m */ public static String getSign(Map<String, String> params, String mchKey) { StringBuilder sb = new StringBuilder(); sb.append(formatBizQueryParaMap(params, false)); // ??string?KEY // sb.append("&key=").append(WxConfigUtil.KEY); sb.append("&key=").append(mchKey); // ??MD5 String result = null; try { result = MD5.getMD5(sb.toString()); } catch (NoSuchAlgorithmException e) { LOG.error(e.getMessage(), e); return result; } // ?? return result.toUpperCase(); }
From source file:com.owncloud.android.utils.EncryptionUtils.java
public static byte[] generateKey() { KeyGenerator keyGenerator;//from www . j a v a 2s . c o m try { keyGenerator = KeyGenerator.getInstance(AES); keyGenerator.init(128); return keyGenerator.generateKey().getEncoded(); } catch (NoSuchAlgorithmException e) { Log_OC.e(TAG, e.getMessage()); } return null; }
From source file:fr.moribus.imageonmap.migration.V3Migrator.java
/** * Calculates the checksum of a given file * @param file The file to calculate the checksum of * @param algorithmName The name of the algorithm to use * @return The resulting checksum in hexadecimal format * @throws IOException /* ww w.ja v a2 s.c o m*/ */ static private String fileCheckSum(File file, String algorithmName) throws IOException { MessageDigest instance; try { instance = MessageDigest.getInstance(algorithmName); } catch (NoSuchAlgorithmException ex) { throw new IOException( "Could not check file integrity because of NoSuchAlgorithmException : " + ex.getMessage()); } FileInputStream inputStream = new FileInputStream(file); byte[] data = new byte[1024]; int read = 0; while ((read = inputStream.read(data)) != -1) { instance.update(data); } byte[] hashBytes = instance.digest(); StringBuilder buffer = new StringBuilder(); char hexChar; for (int i = 0; i < hashBytes.length; i++) { hexChar = Integer.toHexString((hashBytes[i] & 0xff) + 0x100).charAt(0); buffer.append(hexChar); } return buffer.toString(); }
From source file:eap.util.EDcodeUtil.java
private static byte[] hmac(byte[] data, byte[] key, String algorithm) { try {/*w w w. j av a 2s.c o m*/ SecretKey secretKey = new SecretKeySpec(key, algorithm); Mac mac = Mac.getInstance(secretKey.getAlgorithm(), provider); mac.init(secretKey); return mac.doFinal(data); } catch (NoSuchAlgorithmException e) { throw new IllegalArgumentException("No such algorithm [" + algorithm + "]"); } catch (InvalidKeyException e) { throw new IllegalArgumentException(e.getMessage(), e); } }
From source file:com.googlecode.fascinator.authentication.custom.ldap.CustomLdapAuthenticationHandler.java
/** * Method to compare two passwords. The method attempts to encode the user * password based on the ldap password encoding extracted from the storage * format (e.g. {SHA}g0bbl3d3g00ka12@#19/=). *//from w ww . ja v a 2 s . c o m * @param userPassword * the password that the user entered * @param ldapPassword * the password from the ldap directory * @return true if userPassword equals ldapPassword with respect to encoding */ private static boolean passwordsMatch(String userPassword, String ldapPassword) { Matcher m = LDAP_PASSWORD_PATTERN.matcher(ldapPassword); boolean match = false; if (m.find() && m.groupCount() == 2) { // if password is encoded in the LDAP, encode the password before // compare String encoding = m.group(1); String password = m.group(2); if (log.isDebugEnabled()) { log.debug("Encoding: {}, Password: {}", encoding, password); } MessageDigest digest = null; try { digest = MessageDigest.getInstance(encoding.toUpperCase()); } catch (NoSuchAlgorithmException e) { log.error("Unsupported Algorithm used: {}", encoding); log.error(e.getMessage()); return false; } byte[] resultBytes = digest.digest(userPassword.getBytes()); byte[] result = Base64.encodeBase64(resultBytes); String pwd = new String(password); String ldp = new String(result); match = pwd.equals(ldp); } else { // if passwords are not encoded, just do raw compare match = userPassword.equals(ldapPassword); } return match; }
From source file:orca.ektorp.client.ContextualSSLSocketFactory.java
/** * Obtains default SSL socket factory with an SSL context based on the standard JSSE * trust material (<code>cacerts</code> file in the security properties directory). * System properties are not taken into consideration. * * @return default SSL socket factory// www.jav a2 s.c o m */ public static ContextualSSLSocketFactory getSocketFactory() throws SSLInitializationException { SSLContext sslcontext; try { sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, null, null); return new ContextualSSLSocketFactory(sslcontext, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } catch (NoSuchAlgorithmException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } catch (KeyManagementException ex) { throw new SSLInitializationException(ex.getMessage(), ex); } }
From source file:org.openme_ck.openme_ck.java
public static JSONObject convert_str_to_sha1(JSONObject i) { /*/* w w w .j av a2 s . c o m*/ Convert string to sha1 Input: { string - string } Output: { return - return code >0 if not authentificated string_sha1 - password in SHA1 (digest) string_sha1_hex - password in SHA1 (digest in hex) string_sha1_base64 - BASE64 (SHA1 digest) - compatible with htpasswd format } */ byte[] sha1 = null; String sha1_hex = ""; String sha1_base64 = ""; // Prepare return object JSONObject r = new JSONObject(); String x = (String) i.get("string"); if (x == null || x == "") { r.put("return", new Long(1)); r.put("error", "'string' is not set in openme/convert_str_to_sha1"); return r; } try { MessageDigest crypt = MessageDigest.getInstance("SHA-1"); crypt.reset(); crypt.update(x.getBytes("UTF-8")); sha1 = crypt.digest(); sha1_hex = byteToHexString(sha1); sha1_base64 = new String(Base64.encodeBase64(sha1)); } catch (NoSuchAlgorithmException e) { r.put("return", new Long(0)); r.put("error", "can't crypt password (" + e.getMessage() + ") ..."); return r; } catch (UnsupportedEncodingException e) { r.put("return", new Long(0)); r.put("error", "can't crypt password (" + e.getMessage() + ") ..."); return r; } r.put("return", new Long(0)); r.put("string_sha1", sha1.toString()); r.put("string_sha1_hex", sha1_hex); r.put("string_sha1_base64", sha1_base64); return r; }
From source file:be.fedict.eid.dss.spi.utils.XAdESUtils.java
public static void checkSigningCertificate(X509Certificate signingCertificate, SignedSignaturePropertiesType signedSignatureProperties) throws XAdESValidationException, CertificateEncodingException { CertIDListType signingCertificateCertIDList = signedSignatureProperties.getSigningCertificate(); List<CertIDType> signingCertificateCertIDs = signingCertificateCertIDList.getCert(); CertIDType signingCertificateCertID = signingCertificateCertIDs.get(0); DigestAlgAndValueType signingCertificateDigestAlgAndValue = signingCertificateCertID.getCertDigest(); String certXmlDigestAlgo = signingCertificateDigestAlgAndValue.getDigestMethod().getAlgorithm(); String certDigestAlgo = XAdESUtils.getDigestAlgo(certXmlDigestAlgo); byte[] certDigestValue = signingCertificateDigestAlgAndValue.getDigestValue(); MessageDigest messageDigest;//from w ww. j a v a 2 s . com try { messageDigest = MessageDigest.getInstance(certDigestAlgo); } catch (NoSuchAlgorithmException e) { throw new XAdESValidationException("message digest algo error: " + e.getMessage(), e); } byte[] actualCertDigestValue = messageDigest.digest(signingCertificate.getEncoded()); if (!Arrays.equals(actualCertDigestValue, certDigestValue)) { throw new XAdESValidationException( "XAdES signing certificate not corresponding with actual signing certificate"); } X509IssuerSerialType issuerSerial = signingCertificateCertID.getIssuerSerial(); BigInteger serialNumber = issuerSerial.getX509SerialNumber(); if (false == signingCertificate.getSerialNumber().equals(serialNumber)) { throw new XAdESValidationException("xades:SigningCertificate serial number mismatch"); } X509Name issuerName; try { /*issuerName = new X509Name( (ASN1Sequence) new ASN1InputStream(signingCertificate .getIssuerX500Principal().getEncoded()) .readObject());*/ X509Principal sprin = new X509Principal(signingCertificate.getIssuerX500Principal().getEncoded()); //issuerName = new X509Name( signingCertificate.getIssuerX500Principal().getName(X500Principal.RFC1779) ); issuerName = new X509Name(sprin.getName()); } catch (IOException e) { throw new XAdESValidationException("error parsing xades:SigningCertificate ds:X509IssuerName: " + e); } X509Name xadesIssuerName = new X509Name(issuerSerial.getX509IssuerName()); if (false == issuerName.equals(xadesIssuerName)) { throw new XAdESValidationException("xades:SigningCertificate issuer name mismatch"); } LOG.debug("XAdES SigningCertificate OK"); }
From source file:org.openme.openme.java
public static JSONObject convert_str_to_sha1(JSONObject i) { /*/*from w w w .ja v a2s. c o m*/ Convert string to sha1 Input: { cm_string - string } Output: { cm_return - return code >0 if not authentificated cm_string_sha1 - password in SHA1 (digest) cm_string_sha1_hex - password in SHA1 (digest in hex) cm_string_sha1_base64 - BASE64 (SHA1 digest) - compatible with htpasswd format } */ byte[] sha1 = null; String sha1_hex = ""; String sha1_base64 = ""; // Prepare return object JSONObject r = new JSONObject(); String x = (String) i.get("cm_string"); if (x == null || x == "") { r.put("cm_return", new Long(1)); r.put("cm_error", "'cm_string' is not set in openme/convert_str_to_sha1"); return r; } try { MessageDigest crypt = MessageDigest.getInstance("SHA-1"); crypt.reset(); crypt.update(x.getBytes("UTF-8")); sha1 = crypt.digest(); sha1_hex = byteToHexString(sha1); sha1_base64 = new String(Base64.encodeBase64(sha1)); } catch (NoSuchAlgorithmException e) { r.put("cm_return", new Long(0)); r.put("cm_error", "can't crypt password (" + e.getMessage() + ") ..."); return r; } catch (UnsupportedEncodingException e) { r.put("cm_return", new Long(0)); r.put("cm_error", "can't crypt password (" + e.getMessage() + ") ..."); return r; } r.put("cm_return", new Long(0)); r.put("cm_string_sha1", sha1.toString()); r.put("cm_string_sha1_hex", sha1_hex); r.put("cm_string_sha1_base64", sha1_base64); return r; }
From source file:org.exoplatform.services.videocall.AuthService.java
protected static KeyManager[] getKeyManagers(String keyStoreType, InputStream keyStoreFile, String keyStorePassword) throws Exception { KeyStore keyStore = null;//from ww w . j a v a 2s .c om try { keyStore = KeyStore.getInstance(keyStoreType); keyStore.load(keyStoreFile, keyStorePassword.toCharArray()); } catch (NoSuchAlgorithmException e) { if (LOG.isErrorEnabled()) { LOG.error("Java implementation cannot manipulate PKCS12 keystores"); } } catch (KeyStoreException e) { if (LOG.isErrorEnabled()) { LOG.error("Java implementation cannot manipulate PKCS12 keystores"); } } catch (CertificateException e) { if (LOG.isErrorEnabled()) { LOG.error("Bad key or certificate in " + keyStoreFile, e.getMessage()); } } catch (FileNotFoundException e) { if (LOG.isErrorEnabled()) { LOG.error("Could not find or read " + keyStoreFile, e.getMessage()); } } catch (IOException e) { if (LOG.isErrorEnabled()) { LOG.error("PKCS12 password is incorrect or keystore is inconsistent: " + keyStoreFile); } } KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(keyStore, keyStorePassword.toCharArray()); return kmf.getKeyManagers(); }