List of usage examples for java.security NoSuchAlgorithmException getMessage
public String getMessage()
From source file:fi.csc.idp.stepup.impl.DigestChallengeGenerator.java
@Override public String generate(String target) throws Exception { String challenge = ""; // to explicitly support generating empty challenge if (maxLength == 0) { return challenge; }/*from w w w . j a va2 s.c o m*/ try { String time = "" + System.currentTimeMillis(); MessageDigest md = MessageDigest.getInstance(digest); // to make challenge user specific if (target != null) { md.update(target.getBytes()); } // to make challenge installation specific md.update(salt.getBytes()); // to make challenge time specific md.update(time.getBytes()); byte[] buffer = md.digest(); if (useDecimal) { // output a decimal string for (byte data : buffer) { // operation reduces unpredictability a bit challenge += (int) data & 0xFF; } } else { // ouput a hexstring challenge = Hex.encodeHexString(buffer); } } catch (NoSuchAlgorithmException e) { log.error("Unable to generate challenge {}", e.getMessage()); return null; } return challenge.substring(0, challenge.length() > maxLength ? maxLength : challenge.length()); }
From source file:be.fedict.eid.pkira.common.security.AbstractPkiRaAuthenticationResponseService.java
@Override public void validateServiceCertificate(SamlAuthenticationPolicy authenticationPolicy, List<X509Certificate> certificateChain) throws SecurityException { if (certificateChain == null || certificateChain.size() == 0) { throw new SecurityException("Missing certificate chain"); }//from w ww .j a va 2 s.c o m X509Certificate certificate = certificateChain.get(0); MessageDigest md; try { md = MessageDigest.getInstance("SHA1"); md.update(certificate.getEncoded()); byte[] fp = md.digest(); log.info("Actual fingerprint: " + Hex.encodeHexString(fp)); String[] fingerprintConfig = getFingerprints(); if (fingerprintConfig == null || fingerprintConfig.length == 0) { log.warn("No fingerprint given"); return; } boolean ok = false; Hex hex = new Hex(); for (String fingerprint : fingerprintConfig) { log.info("Allowed fingerprint: " + fingerprint); byte[] fpConfig = (byte[]) hex.decode(fingerprint); ok |= java.util.Arrays.equals(fp, fpConfig); } if (!ok) { log.error("Signatures not correct."); throw new SecurityException("Signatures not correct."); } } catch (NoSuchAlgorithmException e) { log.error("No Such Algorithm", e); throw new SecurityException(e.getMessage()); } catch (CertificateEncodingException e) { log.error("Certificate Encoding Exception", e); throw new SecurityException(e.getMessage()); } catch (DecoderException e) { log.error("Fingerprint decode problem", e); throw new SecurityException(e.getMessage()); } catch (Throwable e) { log.error("Exception during service certificate validation", e); throw new SecurityException(e.getMessage()); } }
From source file:com.headstrong.npi.raas.Utils.java
/** * Generate an encrypted string using SHA one-way hashing * /* ww w .ja v a2s .co m*/ * @param password * @return * @throws Exception */ public static String generateEncryptedPassword(String password) throws Exception { MessageDigest messageDigest = null; String encryptedPassword = ""; try { messageDigest = MessageDigest.getInstance("SHA"); messageDigest.update(password.getBytes("UTF-8")); byte rawBytes[] = messageDigest.digest(); encryptedPassword = new String(Base64.encodeBase64(rawBytes)); } catch (NoSuchAlgorithmException e) { throw new Exception(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new Exception(e.getMessage()); } return encryptedPassword; }
From source file:org.atombeat.xquery.functions.util.SaveUploadAs.java
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException { RequestModule reqModule = (RequestModule) context.getModule(RequestModule.NAMESPACE_URI); // request object is read from global variable $request Variable var = reqModule.resolveVariable(RequestModule.REQUEST_VAR); if (var == null || var.getValue() == null) throw new XPathException(this, "No request object found in the current XQuery context."); if (var.getValue().getItemType() != Type.JAVA_OBJECT) throw new XPathException(this, "Variable $request is not bound to an Java object."); JavaObjectValue value = (JavaObjectValue) var.getValue().itemAt(0); if (!(value.getObject() instanceof RequestWrapper)) { throw new XPathException(this, "Variable $request is not bound to a Request object."); }//from w ww . j a v a2 s. co m RequestWrapper request = (RequestWrapper) value.getObject(); // try to copy upload try { String paramName = args[0].getStringValue(); String path = args[1].getStringValue(); File upload = request.getFileUploadParam(paramName); File file = new File(path); InputStream in = new FileInputStream(upload); MessageDigest md5 = MessageDigest.getInstance("MD5"); in = new DigestInputStream(in, md5); OutputStream out = new FileOutputStream(file); Stream.copy(in, out); String signature = new BigInteger(1, md5.digest()).toString(16); return new StringValue(signature); } catch (IOException ioe) { throw new XPathException(this, "An IO exception ocurred: " + ioe.getMessage(), ioe); } catch (NoSuchAlgorithmException e) { throw new XPathException(this, "A message digest exception ocurred: " + e.getMessage(), e); } }
From source file:com.springsource.hq.plugin.tcserver.serverconfig.web.support.UntrustedSSLProtocolSocketFactory.java
public UntrustedSSLProtocolSocketFactory() { super();/*from www . j a v a 2s .co m*/ try { BogusTrustManager trustMan; SSLContext tlsContext; trustMan = new BogusTrustManager(); tlsContext = SSLContext.getInstance("TLS"); tlsContext.init(null, new X509TrustManager[] { trustMan }, null); this.factory = tlsContext.getSocketFactory(); } catch (NoSuchAlgorithmException exc) { throw new IllegalStateException("Unable to get SSL context: " + exc.getMessage()); } catch (KeyManagementException exc) { throw new IllegalStateException( "Unable to initialize ctx " + "with BogusTrustManager: " + exc.getMessage()); } }
From source file:org.akvo.flow.api.FlowApi.java
private String getAuthorization(String query) { String authorization = null;/* w w w .j a v a 2 s.c o m*/ try { SecretKeySpec signingKey = new SecretKeySpec(API_KEY.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); byte[] rawHmac = mac.doFinal(query.getBytes()); authorization = Base64.encodeToString(rawHmac, Base64.DEFAULT); } catch (NoSuchAlgorithmException e) { Log.e(TAG, e.getMessage()); } catch (InvalidKeyException e) { Log.e(TAG, e.getMessage()); } return authorization; }
From source file:org.conqat.engine.bugzilla.lib.SimpleSSLSocketFactory.java
/** * Create new factory./*from w w w .j a v a2 s .c o m*/ * * @throws IllegalStateException * if there is something wrong with SSL support. */ public SimpleSSLSocketFactory() { try { sc = SSLContext.getInstance("SSL"); } catch (NoSuchAlgorithmException e) { throw new IllegalStateException( "Could not find support for SSL. Check your Java installation. " + e.getMessage(), e); } try { TrustManager[] trustAllCerts = new TrustManager[] { new TrustAllCertificatesManager() }; sc.init(null, trustAllCerts, null); } catch (KeyManagementException e) { // should not happen in this context throw new IllegalStateException("Key Management Exception: " + e.getMessage(), e); } }
From source file:info.magnolia.module.files.MD5CheckingFileExtractorOperation.java
protected MessageDigest getMessageDigest() { try {/* w w w . j a v a 2 s . c o m*/ return MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("Can't check files with md5: " + e.getMessage(), e); } }
From source file:org.apache.james.jdkim.mailets.DKIMSign.java
public void init() throws MessagingException { signatureTemplate = getInitParameter("signatureTemplate"); String privateKeyString = getInitParameter("privateKey"); String privateKeyPassword = getInitParameter("privateKeyPassword", null); forceCRLF = getInitParameter("forceCRLF", true); try {/*from w ww .j a v a2 s. co m*/ PKCS8Key pkcs8 = new PKCS8Key(new ByteArrayInputStream(privateKeyString.getBytes()), privateKeyPassword != null ? privateKeyPassword.toCharArray() : null); privateKey = pkcs8.getPrivateKey(); // privateKey = DKIMSigner.getPrivateKey(privateKeyString); } catch (NoSuchAlgorithmException e) { throw new MessagingException("Unknown private key algorythm: " + e.getMessage(), e); } catch (InvalidKeySpecException e) { throw new MessagingException( "PrivateKey should be in base64 encoded PKCS8 (der) format: " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new MessagingException("General security exception: " + e.getMessage(), e); } }
From source file:org.kuali.continuity.admin.dao.jpa.UserLoginDAOImpl.java
private String getPasswordHash(String password) { if (password == null || password.trim().length() == 0) return password; try {//w ww . ja va 2s. com MessageDigest digest = MessageDigest.getInstance("SHA"); digest.reset(); byte[] input = digest.digest(password.getBytes()); return Hex.encodeHexString(input).toUpperCase(); } catch (NoSuchAlgorithmException e) { // TODO: refactor throw new RuntimeException(e.getMessage(), e); } }