List of usage examples for org.apache.commons.codec.digest DigestUtils shaHex
@Deprecated public static String shaHex(String data)
From source file:be.fedict.trust.MemoryCertificateRepository.java
private String getFingerprint(X509Certificate certificate) { byte[] encodedCertificate; try {/* w w w . j a v a 2 s . c o m*/ encodedCertificate = certificate.getEncoded(); } catch (CertificateEncodingException e) { throw new IllegalArgumentException("certificate encoding error: " + e.getMessage(), e); } String fingerprint = DigestUtils.shaHex(encodedCertificate); return fingerprint; }
From source file:com.zb.app.external.wechat.service.WeiXinResponseHandler.java
/** * ????? ???//from ww w. j a va 2 s . c o m * * @param signature ?? * @param timestamp * @param nonce ? * @return */ public boolean validateSignature(String signature, String timestamp, String nonce) { String[] authStrs = new String[] { weixinConfig.getToken(), timestamp, nonce }; Arrays.sort(authStrs); String validateSignature = DigestUtils.shaHex(StringUtils.join(authStrs, "")); return StringUtils.equals(signature, validateSignature); }
From source file:com.klinker.android.dream.util.CacheHelper.java
/** * Hash the location url string so that it isn't too long * @param location the url to hash for a filename * @return the hashed string//from www.ja v a2s. c o m */ private String hash(String location) { return DigestUtils.shaHex(location); }
From source file:com.ebay.pulsar.analytics.metricstore.limitspec.LimitSpecTest.java
private void testOrderByColumnSpec() { String d1 = "d1"; OrderByColumnSpec c1 = new OrderByColumnSpec(d1, SortDirection.descending); assertEquals(d1, c1.getDimension()); assertEquals(SortDirection.descending, c1.getDirection()); String d2 = "d2"; OrderByColumnSpec c2 = new OrderByColumnSpec(d1, SortDirection.descending); assertArrayEquals(c1.cacheKey(), c2.cacheKey()); c2 = new OrderByColumnSpec(d2, SortDirection.descending); assertTrue(!DigestUtils.shaHex(c1.cacheKey()).equals(DigestUtils.shaHex(c2.cacheKey()))); c2 = new OrderByColumnSpec(d1, SortDirection.ascending); assertTrue(!DigestUtils.shaHex(c1.cacheKey()).equals(DigestUtils.shaHex(c2.cacheKey()))); assertTrue(!c1.equals(null));/*from www . j a v a 2 s . co m*/ c2 = new OrderByColumnSpec(null, null); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new OrderByColumnSpec(d2, null); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new OrderByColumnSpec(d1, null); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new OrderByColumnSpec(d1, SortDirection.ascending); assertTrue(!c1.equals(c2)); assertTrue(!c2.equals(c1)); c2 = new OrderByColumnSpec(d1, SortDirection.descending); assertTrue(c1.equals(c2)); assertTrue(c2.equals(c1)); assertTrue(c1.hashCode() == c2.hashCode()); }
From source file:com.dhenton9000.filedownloader.CheckFileHash.java
/** * Performs a expectedFileHash check on a File. * * @return/* ww w . j av a2 s . co m*/ * @throws IOException */ public boolean hasAValidHash() throws IOException { if (this.fileToCheck == null) { throw new FileNotFoundException("File to check has not been set!"); } if (this.expectedFileHash == null || this.typeOfHash == null) { throw new NullPointerException("Hash details have not been set!"); } if (!this.fileToCheck.exists()) { throw new FileNotFoundException("File '" + fileToCheck.getCanonicalPath() + "' not found"); } String actualFileHash = ""; boolean isHashValid = false; switch (this.typeOfHash) { case MD5: actualFileHash = DigestUtils.md5Hex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) { isHashValid = true; } break; case SHA1: actualFileHash = DigestUtils.shaHex(new FileInputStream(this.fileToCheck)); if (this.expectedFileHash.equals(actualFileHash)) { isHashValid = true; } break; } LOG.info("Filename = '" + this.fileToCheck.getName() + "'"); LOG.info("Expected Hash = '" + this.expectedFileHash + "'"); LOG.info("Actual Hash = '" + actualFileHash + "'"); return isHashValid; }
From source file:com.ebay.pulsar.analytics.metricstore.druid.postaggregator.PostAggregatorTest.java
public void testArithmeticPostAggregator() { String postAggrName = "ArithmeticTest"; List<BasePostAggregator> fields = new ArrayList<BasePostAggregator>(); String funcName = "+"; String postAggrName1 = "PostAggrName1"; String postAggrName2 = "PostAggrName2"; String fieldName1 = "FieldName1"; String fieldName2 = "FieldName2"; FieldAccessorPostAggregator field1 = new FieldAccessorPostAggregator(postAggrName1, fieldName1); FieldAccessorPostAggregator field2 = new FieldAccessorPostAggregator(postAggrName2, fieldName2); fields.add(field1);// w w w .j a v a2s . c o m fields.add(field2); ArithmeticPostAggregator arithPostAggr = new ArithmeticPostAggregator(postAggrName, funcName, fields); List<BasePostAggregator> fieldsGot = arithPostAggr.getFields(); FieldAccessorPostAggregator field01 = (FieldAccessorPostAggregator) fieldsGot.get(0); FieldAccessorPostAggregator field02 = (FieldAccessorPostAggregator) fieldsGot.get(1); assertEquals("1st Field Names NOT EQUAL'", field1.getName(), field01.getName()); assertEquals("2nd Field Names NOT EQUAL'", field2.getName(), field02.getName()); String funcName1 = arithPostAggr.getFn(); assertEquals("Func Names NOT EQUAL'", funcName, funcName1); byte[] cacheKey = arithPostAggr.cacheKey(); String hashCacheKeyExpected = "d86ce360fa6ee1fc3fe211beacc8df8f151fa5db"; String hashCacheKeyGot = DigestUtils.shaHex(cacheKey); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected, hashCacheKeyGot); String postAggrName01 = "ArithmeticTest01"; List<BasePostAggregator> fields1 = new ArrayList<BasePostAggregator>(); fields1.add(field1); ArithmeticPostAggregator arithPostAggr1 = new ArithmeticPostAggregator(postAggrName01, funcName, fields1); byte[] cacheKey1 = arithPostAggr1.cacheKey(); String hashCacheKeyExpected1 = "4dd11e0f70f0d89384d0e5a6e373c6ea722b7895"; String hashCacheKeyGot1 = DigestUtils.shaHex(cacheKey1); assertEquals("Hash of cacheKey NOT Equals", hashCacheKeyExpected1, hashCacheKeyGot1); PostAggregatorType type = arithPostAggr.getType(); assertEquals("Type NOT Equals", PostAggregatorType.arithmetic, type); //PostAggregatorCacheHelper cacheHelper = new PostAggregatorCacheHelper (); // String postAggrName = "ArithmeticTest"; // List<BasePostAggregator> fields = new ArrayList<BasePostAggregator> (); // String funcName = "+"; // // String postAggrName1 = "PostAggrName1"; // String postAggrName2 = "PostAggrName2"; // String fieldName1 = "FieldName1"; // String fieldName2 = "FieldName2"; // FieldAccessorPostAggregator field1 = new FieldAccessorPostAggregator(postAggrName1, fieldName1); // FieldAccessorPostAggregator field2 = new FieldAccessorPostAggregator(postAggrName2, fieldName2); // fields.add(field1); // fields.add(field2); ArithmeticPostAggregator postAggr0 = new ArithmeticPostAggregator(postAggrName, funcName, fields); assertTrue(postAggr0.equals(arithPostAggr)); assertTrue(postAggr0.equals(postAggr0)); ArithmeticPostAggregator postAggr = new ArithmeticPostAggregator(null, null); assertTrue(!postAggr.equals(postAggr0)); assertTrue(!postAggr0.equals(postAggr)); postAggr = new ArithmeticPostAggregator(postAggrName, null); assertTrue(!postAggr.equals(postAggr0)); assertTrue(!postAggr0.equals(postAggr)); postAggr = new ArithmeticPostAggregator(postAggrName, funcName); assertTrue(!postAggr.equals(postAggr0)); assertTrue(!postAggr0.equals(postAggr)); postAggr = new ArithmeticPostAggregator(postAggrName, funcName, fields); assertTrue(postAggr.equals(postAggr0)); assertTrue(postAggr0.equals(postAggr)); assertTrue(postAggr.hashCode() == postAggr0.hashCode()); assertTrue(!postAggr.equals(new Object())); }
From source file:com.ideabase.repository.test.api.UserServiceTest.java
/** * Ensure user service can authenticate user credentials. * Successful authentication ended with a {@code User} profile object. */// w ww. ja v a 2s .com public void testLogin() { final String userName = "veryrandom-user" + Math.random(); final String password = DigestUtils.shaHex("password is md5"); // create user final Integer userId = TestCaseRepositoryHelper.fixCreateUser(mUserService, userName, password); // authenticate user final UserCredential userCredential = new UserCredential(userName, password); // authenticate user. final Subject subject = mUserService.login(userCredential); // retrieve user principal. final RepositoryUserPrincipal principal = subject.getPrincipals(RepositoryUserPrincipal.class).iterator() .next(); // verify assertNotNull("Authentication failed.", subject); assertNotNull("Authenticated user principal is null.", principal); assertNotNull("Authenticated user id is not attached with principal.", principal.getId()); LOG.debug("Subject - " + subject); }
From source file:com.bearstouch.android.core.InstallTracker.java
private String getIDFromFile(Context ctx) { SharedPreferences mSettings = null;//from w ww .java 2s.c om mSettings = getPreferenceFile(); mLg.info("Verifying Install Info"); mUniqueID = mSettings.getString(UNIQUE_KEYID, ""); if (mUniqueID.length() == 0) { // Application First run mLg.info("First Time Running - Generating Unique Install ID"); mIsFirstTimeRunnig = true; mIsAValidInstall = true; mUniqueID = UUID.randomUUID().toString(); mInstallTimeStamp = System.currentTimeMillis(); mTimeStampHash = DigestUtils.shaHex(mUniqueID + Long.toString(mInstallTimeStamp)); saveToPreferencesFile(ctx, mSettings, mUniqueID, mInstallTimeStamp, mTimeStampHash); mLg.info("Install Info Saved with Success"); return mUniqueID; } else { mLg.info("Not First Time Running - Validating Install"); mTimeStampHash = mSettings.getString(TIMESTAMP_HASH_KEY, ""); mInstallTimeStamp = mSettings.getLong(INSTALL_TIMESTAMP_KEY, 0); mIsAValidInstall = verifyInstallID(); if (!mIsAValidInstall) { mLg.error("Invalid Install = " + mUniqueID); } else { mLg.info("Unique ID Loaded = " + mUniqueID); } return mUniqueID; } }
From source file:edu.psu.citeseerx.utility.FileDigest.java
/** * Calculates a file's SHA-1 digest and returns it as a 32 character hex string * @param toDigest//from ww w .ja v a 2 s.c o m * @return SHA-1 digest as a hex string */ public static String sha1Hex(File toDigest) { byte[] fileContent = getFileContent(toDigest); return DigestUtils.shaHex(fileContent); }
From source file:com.netease.hearttouch.hthotfix.patch.PatchSoHelper.java
/** * ?CPU??so//from w w w. j a v a 2 s .c om */ public int collectSoFiles() { HashMap<String, String> hashMap = HashFileHelper .parse(Constants.getHotfixPath(project, Constants.HOTFIX_SO_HASH)); soFileMap = new HashMap<>(); for (HashMap.Entry<String, String> entry : hashMap.entrySet()) { String soPath = project.getProjectDir().toString() + entry.getKey(); File soFile = new File(soPath); if (!soFile.exists()) continue; String archName = soFile.getParentFile().getName(); if (onlyARM && !archName.equals("armeabi")) continue; String soHash = entry.getValue(); try { String sha1Hex = DigestUtils.shaHex(Files.readAllBytes(soFile.toPath())); if (!sha1Hex.equals(soHash)) { if (soFileMap.containsKey(archName)) { ArrayList<File> soFileList = soFileMap.get(archName); soFileList.add(soFile); } else { ArrayList<File> soFileList = new ArrayList<>(); soFileList.add(soFile); soFileMap.put(archName, soFileList); } } } catch (IOException ioe) { ioe.printStackTrace(); } } return soFileMap.size(); }