List of usage examples for org.apache.commons.codec.binary Hex encodeHex
public static char[] encodeHex(byte[] data)
From source file:com.netflix.explorers.resources.MinifiedContentResource.java
@GET @Path("/{subResources:.*}") public Response get(@PathParam("subResources") String subResources) throws Exception { LOG.debug(subResources);/* w w w . ja v a 2 s . c o m*/ String ext = StringUtils.substringAfterLast(subResources, "."); String mediaType = EXT_TO_MEDIATYPE.get(ext); final Map<String, Object> vars = new HashMap<String, Object>(); RequestContext requestContext = manager.newRequestContext(null); vars.put("RequestContext", requestContext); vars.put("Global", manager.getGlobalModel()); vars.put("Explorers", manager); try { CacheControl cc = new CacheControl(); cc.setMaxAge(MAX_AGE); cc.setNoCache(false); return Response.ok(SharedFreemarker.getInstance().render(subResources + ".ftl", vars), mediaType) .cacheControl(cc).expires(new Date(System.currentTimeMillis() + 3600 * 1000)) .tag(new String( Hex.encodeHex(MessageDigest.getInstance("MD5").digest(subResources.getBytes())))) .build(); } catch (Exception e) { LOG.error(e.getMessage()); throw e; } }
From source file:cec.easyshop.storefront.security.impl.DefaultGUIDCookieStrategy.java
protected String createGUID() { final String randomNum = String.valueOf(getRandom().nextInt()); final byte[] result = getSha().digest(randomNum.getBytes()); return String.valueOf(Hex.encodeHex(result)); }
From source file:corner.services.impl.DESedeEncryptServiceImpl.java
public String encrypt(final String src) { if (src == null) return null; try {/* w w w .j a v a 2s . c om*/ // byte[] encoded = encrypt(src.getBytes(CHIPERH_CHARSET), cipher.getCipher()); // ? return new String(Hex.encodeHex(encoded)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return null; }
From source file:com.github.aelstad.keccakj.fips202.KeccackDigestTestUtils.java
public void runTests(List<DigestTest> tests, AbstractKeccackMessageDigest messageDigest, int digestLength) throws Exception { for (DigestTest dt : tests) { messageDigest.reset();//from w w w. j av a2 s .com if ((dt.len & 7) == 0) messageDigest.update(dt.msg, 0, dt.len >> 3); else messageDigest.engineUpdateBits(dt.msg, 0, dt.len); System.out.println("Rate is now " + new String( Hex.encodeHex(messageDigest.getRateBits(0, Math.min(dt.len, messageDigest.getRateBits()))))); byte[] md = messageDigest.digest(); System.out.println("Testing length " + dt.len + ". Got " + new String(Hex.encodeHex(md))); Assert.assertTrue(digestLength == dt.digest.length); ; Assert.assertTrue(digestLength == md.length); ; org.junit.Assert.assertTrue(Arrays.equals(md, dt.digest)); } testPerformance(messageDigest); }
From source file:com.zimbra.cs.account.ExtAuthTokenKey.java
public String getEncoded() { return version + ":" + created + ":" + new String(Hex.encodeHex(key)); }
From source file:com.ubergeek42.WeechatAndroid.utils.UntrustedCertificateDialog.java
public String getCertificateDescription() { String fingerprint;/*from w w w .j a va2 s. co m*/ try { fingerprint = new String(Hex.encodeHex(DigestUtils.sha256(certificate.getEncoded()))); } catch (CertificateEncodingException e) { fingerprint = getString(R.string.ssl_cert_dialog_unknown_fingerprint); } return getString(R.string.ssl_cert_dialog_description, certificate.getSubjectDN().getName(), certificate.getIssuerDN().getName(), DateFormat.getDateTimeInstance().format(certificate.getNotBefore()), DateFormat.getDateTimeInstance().format(certificate.getNotAfter()), fingerprint); }
From source file:com.cedarsoft.serialization.jackson.test.UserDetailsSerializer.java
@Override public void serialize(@Nonnull JsonGenerator serializeTo, @Nonnull UserDetails object, @Nonnull Version formatVersion) throws IOException, VersionException, JsonProcessingException { serializeTo.writeNumberField(PROPERTY_REGISTRATION_DATE, object.getRegistrationDate()); serializeTo.writeNumberField(PROPERTY_LAST_LOGIN, object.getLastLogin()); serializeTo.writeStringField(PROPERTY_PASSWORD_HASH, new String(Hex.encodeHex(object.getPasswordHash()))); }
From source file:it.crs4.seal.read_sort.FastaChecksummer.java
public void calculate() throws FormatException, java.io.IOException { if (input == null) throw new IllegalStateException("FastaChecksummer input not set"); contigHashes = new HashMap<String, ChecksumEntry>(); String currentContig = null;/*from w w w .j a v a 2s.co m*/ java.security.MessageDigest hasher = null; try { hasher = java.security.MessageDigest.getInstance(checksumAlgorithm); } catch (java.security.NoSuchAlgorithmException e) { throw new RuntimeException( "Unexpected NoSuchAlgorithmException when asking for " + checksumAlgorithm + " algorithm"); } String line = input.readLine(); if (line == null) throw new FormatException("empty Fasta"); try { while (line != null) { if (line.startsWith(">")) // start a new contig { if (currentContig != null) { // Hadoop 0.20,2 ships with Apache commons version 1.3, which doesn't // have encodeHexString String cs = new String(Hex.encodeHex(hasher.digest())); contigHashes.put(currentContig, new ChecksumEntry(currentContig, cs)); } Matcher m = ContigNamePattern.matcher(line); if (m.matches()) { currentContig = m.group(1); hasher.reset(); } else throw new FormatException("Unexpected contig name format: " + line); } else { if (currentContig == null) throw new FormatException( "Sequence outside any fasta record (header is missing). Line: " + line); else hasher.update(line.getBytes("US-ASCII")); } line = input.readLine(); } if (currentContig != null) // store the last contig { String cs = new String(Hex.encodeHex(hasher.digest())); contigHashes.put(currentContig, new ChecksumEntry(currentContig, cs)); } } catch (java.io.UnsupportedEncodingException e) { throw new RuntimeException("Unexpected UnsupportedEncodingException! Line: " + line); } }
From source file:lt.bsprendimai.ddesk.UserHandler.java
public String login() { try {//from w w w . ja v a 2 s . c om char[] pwdMD5 = Hex.encodeHex(MessageDigest.getInstance("MD5").digest(user.getPassword().getBytes())); String password = new String(pwdMD5); if (password.length() < 32) { for (int i = (32 - password.length()); i > 0; i--) { password = "0" + password; } } Query q = SessionHolder.currentSession().getSess().createQuery( " FROM " + Person.class.getName() + " WHERE lower(loginCode) = lower(?) AND password = ? "); q.setString(0, user.getLoginCode().trim()); q.setString(1, password.trim()); List l = q.list(); if (q.list().isEmpty()) { loggedIn = false; user.setName(null); user.setPassword(null); if (this.userLocale == null) this.userLocale = Locale.getDefault(); String message = UIMessenger.getMessage(this.userLocale, "application.login.error"); UIMessenger.addErrorMessage(message, ""); return StandardResults.FAIL; } else { loggedIn = true; user = (Person) l.get(0); lastLogin = user.getLastLogin(); user.setLastLogin(new Date()); user.update(); this.userLocale = ParameterAccess.getLocale(user.getLanguage()); new ParameterAccess().setLanguage(user.getLanguage()); email = user.getEmail(); phone = user.getPhoneNo(); for (Entry<Integer, String> c : ParameterAccess.getLanguages().entrySet()) { if (c.getValue().equals(user.getLanguage())) this.setLanguage(c.getKey()); } restoreFilter(); if (user.getCompany() == Company.OWNER || user.getLoginLevel() == Person.PARTNER) { return StandardResults.INTRANET; } else { company = (Company) SessionHolder.currentSession().getSess() .createQuery(" FROM " + Company.class.getName() + " WHERE id = ?") .setInteger(0, user.getCompany()).uniqueResult(); contract = (CompanyContract) SessionHolder.currentSession().getSess() .createQuery(" FROM " + CompanyContract.class.getName() + " WHERE company = ?") .setInteger(0, user.getCompany()).uniqueResult(); return StandardResults.SUCCESS; } } } catch (Exception ex) { SessionHolder.endSession(); UIMessenger.addFatalKeyMessage("error.transaction.abort", getUserLocale()); ex.printStackTrace(); return StandardResults.FAIL; } }
From source file:com.google.feedserver.util.EncryptionUtil.java
/** * Encrypts the given string using a symmetric key algorithm * /*from w w w. j av a 2s .c o m*/ * @param input The input * @return The encrypted string with hex representation * @throws InvalidKeyException * @throws BadPaddingException * @throws IllegalBlockSizeException * @throws NoSuchPaddingException * @throws NoSuchAlgorithmException */ public String encrypt(String input) throws InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, NoSuchPaddingException { Cipher cipher = Cipher.getInstance(algorithm); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] inputBytes = input.getBytes(); byte[] encryptedBytes = cipher.doFinal(inputBytes); String encryptedValue = new String(Hex.encodeHex(encryptedBytes)); return encryptedValue; }