List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:com.omertron.yamjtrakttv.model.Credentials.java
public void setPassword(String password) { // If the password is not 40 characters it's probably plain text, so encode it if (password.length() != 40) { this.password = DigestUtils.shaHex(password); } else {/* w w w . j av a2s .c o m*/ this.password = password; } }
From source file:com.payu.sdk.helper.SignatureHelper.java
/** * builds the signature for the transaction * * @param order The order that will have the signature * @param merchantId The merchantId into the signature * @param key The apiKey of the merchant * @param valueFormat The format to use for decimal values * @param algorithm The algorithm to use * @return the full signature to use/*from ww w . j a v a 2 s .c o m*/ */ public static String buildSignature(Order order, Integer merchantId, String key, String valueFormat, String algorithm) { String message = buildMessage(order, merchantId, key, valueFormat); if (MD5_ALGORITHM.equalsIgnoreCase(algorithm)) { return DigestUtils.md5Hex(message); } else if (SHA_ALGORITHM.equalsIgnoreCase(algorithm)) { return DigestUtils.shaHex(message); } else { throw new IllegalArgumentException("Could not create signature. Invalid algoritm"); } }
From source file:com.ebay.pulsar.analytics.metricstore.druid.having.HavingTest.java
public void testAndHaving() { List<BaseHaving> fields = new ArrayList<BaseHaving>(); String dim1 = "Aggregate1"; String dim2 = "Aggregate2"; String val1 = "Value1"; String val2 = "Value1"; EqualToHaving having1 = new EqualToHaving(dim1, val1); EqualToHaving having2 = new EqualToHaving(dim2, val2); fields.add(having1);//from w ww . j a v a 2 s .co m fields.add(having2); AndHaving andHaving = new AndHaving(fields); byte[] cacheKey = andHaving.cacheKey(); String hashCacheKeyExpected = "f9f8bfd569626ac92de64f4a481942b0b2f4221e"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); List<BaseHaving> fieldZ = andHaving.getHavingSpecs(); EqualToHaving having01 = (EqualToHaving) fieldZ.get(0); EqualToHaving having02 = (EqualToHaving) fieldZ.get(1); assertEquals("Having1 aggregates NOT Equals", having1.getAggregation(), having01.getAggregation()); assertEquals("Having1 values NOT Equals", having1.getValue(), having01.getValue()); assertEquals("Having2 aggregates NOT Equals", having2.getAggregation(), having02.getAggregation()); assertEquals("Having2 values NOT Equals", having2.getValue(), having02.getValue()); HavingType type = andHaving.getType(); assertEquals("AndHaving type NOT Equals", HavingType.and, type); // Nothing to do for HavingCacheHelper //HavingCacheHelper cacheHelper = new HavingCacheHelper(); List<BaseHaving> fields2 = new ArrayList<BaseHaving>(); String dim21 = "Aggregate21"; String dim22 = "Aggregate22"; String val21 = "Value21"; String val22 = "Value21"; EqualToHaving having21 = new EqualToHaving(dim21, val21); EqualToHaving having22 = new EqualToHaving(dim22, val22); fields2.add(having21); fields2.add(having22); AndHaving andHaving2 = new AndHaving(fields2); AndHaving andHaving1 = new AndHaving(null); assertTrue(!andHaving2.equals(andHaving1)); assertTrue(!andHaving1.equals(andHaving2)); andHaving1 = new AndHaving(fields2); assertTrue(andHaving2.equals(andHaving1)); assertTrue(andHaving2.hashCode() == andHaving1.hashCode()); assertTrue(andHaving2.equals(andHaving2)); assertTrue(!andHaving2.equals(new NotHaving(having22) { })); }
From source file:com.boozallen.cognition.ingest.storm.bolt.starter.FlattenJsonBolt.java
@Override protected void execute(Tuple input, RecordCollector collector) { byte[] bytes = (byte[]) input.getValue(0); String record = new String(bytes); String sha1Checksum = DigestUtils.shaHex(bytes); if (StringUtils.isBlank(record)) { // skips blank entries logger.info("received blank record"); return;/*w w w . j a v a2 s. co m*/ } try { LogRecord logRecord = new LogRecord(sha1Checksum); logRecord.addMetadataValue(SHA1_CHECKSUM, sha1Checksum); parseJson(record, logRecord); collector.emit(logRecord); } catch (Exception e) { // Not bubbling up, since it would fail the entire tuple // Parsing failure would not be fixed even after a replay... logger.error("Failed to process tuple: " + record, e); } }
From source file:au.edu.ausstage.terminator.AuthenticationManager.java
/** * A method to generate a hash and return a base64 encoded string * * @param toHash the string to hash//from w ww .ja v a 2s . c o m * * @return the base64 encoded string of the hash */ private String doHash(String toHash) { // check the parameters if (toHash == null) { throw new RuntimeException("Missing required parameter"); } return DigestUtils.shaHex(toHash); }
From source file:controller.action.postactions.CreateAccount.java
/** * Create new account if all required fildes are filled correctly * //from w w w .jav a 2 s . co m * @throws ServletException * @throws IOException */ @Override public void doExecute() throws ServletException, IOException { String name = request.getParameter("name"); String lastName = request.getParameter("lastname"); String email = request.getParameter("email"); String password = request.getParameter("password"); String confirmPassword = request.getParameter("confirmPassword"); UserCreator userCreator = new UserCreator(); User newUser = null; User dbUser = null; String errorMessage = checkAllFields(name, lastName, email, password, confirmPassword); if (errorMessage != null) { saveFieldValues(name, lastName, email); sendRedirect(null, errorMessage, "link.signup"); return; // setMessages(null, errorMessage); // return ConfigManager.getProperty("path.page.signup"); } try { if (userCreator.getUserByEmail(email) != null) { saveFieldValues(name, lastName, email); sendRedirect(null, "signup.errormessage.existinguser", "link.signup"); return; // setMessages(null, "signup.errormessage.existinguser"); // return ConfigManager.getProperty("path.page.signup"); } String hexPassword = DigestUtils.shaHex(password); newUser = new User(name, lastName, email, hexPassword); if (!userCreator.insertUser(newUser)) { throw new SQLException(); } dbUser = (User) userCreator.getUserByEmail(email); if (dbUser == null) { throw new SQLException(); } } catch (SQLException ex) { saveFieldValues(name, lastName, email); sendRedirect(null, "exception.errormessage.sqlexception", "link.signup"); return; // setMessages(null, "exception.errormessage.sqlexception"); // return ConfigManager.getProperty("path.page.signup"); } catch (ServerOverloadedException ex) { saveFieldValues(name, lastName, email); sendRedirect(null, "exception.errormessage.serveroverloaded", "link.signup"); return; // setMessages(null, "exception.errormessage.serveroverloaded"); // return ConfigManager.getProperty("path.page.signup"); } session.setAttribute("user", dbUser); sendRedirect(null, null, "link.profile"); // return null; }
From source file:com.metamx.druid.merger.common.task.MergeTaskTest.java
@Test public void testID() { final String desiredPrefix = "merge_foo_" + DigestUtils.shaHex("2012-01-03T00:00:00.000Z_2012-01-05T00:00:00.000Z_V1_0" + "_2012-01-04T00:00:00.000Z_2012-01-06T00:00:00.000Z_V1_0" + "_2012-01-05T00:00:00.000Z_2012-01-07T00:00:00.000Z_V1_0") + "_"; Assert.assertEquals(desiredPrefix, testMergeTask.getId().substring(0, desiredPrefix.length())); }
From source file:com.relecotech.bbb.api.APIGenerator.java
public String createAPI(String action, String parameter) { api = action + parameter + SALT;/*from w w w . j a v a2 s . c om*/ System.out.println("api=" + api); String md6 = DigestUtils.shaHex(api); System.out.println("md6=" + md6); checksum = "&checksum=" + DigestUtils.shaHex(api); // api="createname=Test+Meeting&meetingID=abc123&attendeePW=111222&moderatorPW=333444"+SALT; apiWithChecksum = server + action + "?" + parameter + checksum; System.out.println("final api to call=" + apiWithChecksum); return apiWithChecksum; }
From source file:io.apiman.gateway.engine.policies.auth.JDBCIdentityValidator.java
/** * @see io.apiman.gateway.engine.policies.auth.IIdentityValidator#validate(java.lang.String, java.lang.String, io.apiman.gateway.engine.beans.ServiceRequest, io.apiman.gateway.engine.policy.IPolicyContext, java.lang.Object, io.apiman.gateway.engine.async.IAsyncHandler) *///from w w w . ja v a2 s.co m @Override public void validate(String username, String password, ServiceRequest request, IPolicyContext context, JDBCIdentitySource config, IAsyncResultHandler<Boolean> handler) { DataSource ds = lookupDatasource(config); String sqlPwd = password; switch (config.getHashAlgorithm()) { case MD5: sqlPwd = DigestUtils.md5Hex(password); break; case SHA1: sqlPwd = DigestUtils.shaHex(password); break; case SHA256: sqlPwd = DigestUtils.sha256Hex(password); break; case SHA384: sqlPwd = DigestUtils.sha384Hex(password); break; case SHA512: sqlPwd = DigestUtils.sha512Hex(password); break; case None: default: break; } String query = config.getQuery(); Connection conn = null; boolean validated = false; try { conn = ds.getConnection(); conn.setReadOnly(true); PreparedStatement statement = conn.prepareStatement(query); statement.setString(1, username); statement.setString(2, sqlPwd); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { validated = true; } resultSet.close(); } catch (Exception e) { throw new RuntimeException(e); } finally { if (conn != null) { try { conn.close(); } catch (SQLException e) { } } } handler.handle(AsyncResultImpl.create(validated)); }
From source file:com.scorpio4.vendor.sesame.fn.Contrive.java
public String _evaluate(String prefixURI, Value... args) { // get the contrived values (multi-part keys) StringBuilder contrived = new StringBuilder(); for (int i = 1; i < args.length; i++) contrived.append(args[i].stringValue()); // append the SHA hash of the contrived values to the prefix return prefixURI + DigestUtils.shaHex(contrived.toString()); }