List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:com.alibaba.openapi.client.util.SignatureUtil.java
public static byte[] hmacSha1(String[] datas, SecretKeySpec signingKey) { Mac mac;//from w w w . j a v a2 s . c o m try { mac = Mac.getInstance(HMAC_SHA1); mac.init(signingKey); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e.getMessage(), e); } catch (InvalidKeyException e) { throw new IllegalStateException(e.getMessage(), e); } for (String data : datas) { mac.update(data.getBytes(CHARSET_UTF8)); } return mac.doFinal(); }
From source file:org.entrystore.repository.security.Password.java
public static String sha256(String s) { MessageDigest digester;//from www . java 2s . c om try { digester = MessageDigest.getInstance("SHA-256"); digester.update(s.getBytes("UTF-8")); byte[] key = digester.digest(); SecretKeySpec spec = new SecretKeySpec(key, "AES"); return Base64.encodeBase64String(spec.getEncoded()); } catch (NoSuchAlgorithmException nsae) { log.error(nsae.getMessage()); } catch (UnsupportedEncodingException uee) { log.error(uee.getMessage()); } return null; }
From source file:org.apache.maven.plugin.install.DualDigester.java
static MessageDigest getDigester(String algorithm) { try {/*w w w . j a v a 2s. com*/ return MessageDigest.getInstance(algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Unable to initialize digest " + algorithm + " : " + e.getMessage()); } }
From source file:org.springframework.security.saml.trust.UntrustedCertificateException.java
private static void appendThumbPrint(X509Certificate cert, String hash, StringBuilder sb) { try {/*w ww . j a va 2s . com*/ MessageDigest md = MessageDigest.getInstance(hash); byte[] der = cert.getEncoded(); md.update(der); byte[] digest = md.digest(); char[] encode = Hex.encodeHex(digest); appendHexSpace(encode, sb); } catch (NoSuchAlgorithmException e) { sb.append("Error calculating thumbprint: " + e.getMessage()); } catch (CertificateEncodingException e) { sb.append("Error calculating thumbprint: " + e.getMessage()); } }
From source file:com.alibaba.openapi.client.util.SignatureUtil.java
public static byte[] hmacSha1(String path, List<NameValuePair> parameters, SecretKeySpec signingKey) { Mac mac;// ww w . j a v a2 s. c o m try { mac = Mac.getInstance(HMAC_SHA1); mac.init(signingKey); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException(e.getMessage(), e); } catch (InvalidKeyException e) { throw new IllegalStateException(e.getMessage(), e); } mac.update(path.getBytes(CHARSET_UTF8)); Collections.sort(parameters, new NameValuePairComparator<NameValuePair>()); for (NameValuePair parameter : parameters) { mac.update(parameter.getName().getBytes(CHARSET_UTF8)); mac.update(parameter.getValue().getBytes(CHARSET_UTF8)); } return mac.doFinal(); }
From source file:com.cprassoc.solr.auth.security.Sha256AuthenticationProvider.java
public static String sha256(String password, String saltKey) { MessageDigest digest;/*from w w w.j a v a 2s .co m*/ try { digest = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { log.error(e.getMessage(), e); return null;//should not happen } if (saltKey != null) { digest.reset(); digest.update(Base64.decodeBase64(saltKey)); } byte[] btPass = digest.digest(password.getBytes(StandardCharsets.UTF_8)); digest.reset(); btPass = digest.digest(btPass); return Base64.encodeBase64String(btPass); }
From source file:Main.java
/** * Compute the HMAC with SHA-256 of data, as defined in * http://tools.ietf.org/html/rfc2104#section-2 . * @param key The key byte array./*from w w w.j a v a2 s . c o m*/ * @param data The input byte buffer. This does not change the position. * @return The HMAC result. */ public static byte[] computeHmacWithSha256(byte[] key, ByteBuffer data) { final String algorithm = "HmacSHA256"; Mac mac; try { mac = Mac.getInstance(algorithm); } catch (NoSuchAlgorithmException ex) { // Don't expect this to happen. throw new Error("computeHmac: " + algorithm + " is not supported: " + ex.getMessage()); } try { mac.init(new SecretKeySpec(key, algorithm)); } catch (InvalidKeyException ex) { // Don't expect this to happen. throw new Error("computeHmac: Can't init " + algorithm + " with key: " + ex.getMessage()); } int savePosition = data.position(); mac.update(data); data.position(savePosition); return mac.doFinal(); }
From source file:cascading.tap.hadoop.FSDigestInputStream.java
/** * Method getMD5Digest returns the MD5Digest of this FSDigestInputStream object. * * @return the MD5Digest (type MessageDigest) of this FSDigestInputStream object. * @throws IOException when//w ww . j a va 2s . c o m */ private static MessageDigest getMD5Digest() throws IOException { try { return MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException exception) { throw new IOException("digest not found: " + exception.getMessage()); } }
From source file:com.clustercontrol.accesscontrol.factory.LoginUserSelector.java
private static String hash(String password) { MessageDigest md = null;/*from w ww. j ava 2 s .c o m*/ try { md = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { m_log.info("hash() : " + e.getClass().getSimpleName() + ", " + e.getMessage()); return null; } return Base64.encodeBase64String(md.digest(password.getBytes())); }
From source file:at.bitfire.davdroid.webdav.TlsSniSocketFactory.java
private static SSLContext initializedContext(SSLContext sslContext) { verifyAndroidContextSet();//from w ww .j av a 2s . c o m if (sslContext == null) { try { sslContext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e) { Log.wtf(TAG, "TLS not supported: " + e.getMessage()); throw new RuntimeException("No support for TLS!"); } } try { sslContext.init(null, MemorizingTrustManager.getInstanceList(androidContext), null); } catch (KeyManagementException e) { Log.wtf(TAG, "Ignoring unexpected KeyManagementException: " + e.getMessage()); } return sslContext; }