List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex
public static String md5Hex(String data)
From source file:br.com.senac.Bean.UsuarioBean.java
public void salvar() { try {//from ww w . jav a2 s .co m UsuarioDAO usuarioDAO = new UsuarioDAO(); usuario.setSenha(DigestUtils.md5Hex(usuario.getSenha())); usuarioDAO.merge(usuario); usuario = new Usuario(); TipoDAO tipoDAO = new TipoDAO(); tipos = tipoDAO.listar(); CidadeDAO cidadeDAO = new CidadeDAO(); cidades = cidadeDAO.listar(); EstadoDAO estadoDAO = new EstadoDAO(); estados = estadoDAO.listar(); usuarios = usuarioDAO.listar(); Messages.addGlobalInfo("Usurio salvo com sucesso"); } catch (RuntimeException erro) { Messages.addFlashGlobalError("Ocorreu um erro ao tentar salvar um novo Usurio"); erro.printStackTrace(); } }
From source file:com.microsoftopentechnologies.windowsazurestorage.helper.UtilsTest.java
/** * Test of getMD5 method, of class Utils. *//*from w w w .j a v a 2 s . c o m*/ @Test public void testGetMD5() { System.out.println("getMD5"); String plainText = "this is a test for md5 hash"; String expResult = DigestUtils.md5Hex(plainText); String result = Utils.getMD5(plainText); assertEquals(expResult, result); }
From source file:co.kuali.rice.kew.notes.service.impl.S3AttachmentServiceImpl.java
@Override public byte[] findAttachedFile(Attachment attachment) throws Exception { if (!isS3IntegrationEnabled()) { return super.findAttachedFile(attachment); }// www.ja va 2 s . com try { final Object s3File = riceS3FileService.retrieveFile(attachment.getFileDataId()); byte[] s3Bytes = null; byte[] fsBytes = null; if (s3File != null) { if (LOG.isDebugEnabled()) { final Method getFileMetaData = s3File.getClass() .getMethod(RiceAttachmentDataS3Constants.GET_FILE_META_DATA_METHOD); LOG.debug("data found in S3, existing id: " + attachment.getFileDataId() + " metadata: " + getFileMetaData.invoke(s3File)); } final Method getFileContents = s3File.getClass() .getMethod(RiceAttachmentDataS3Constants.GET_FILE_CONTENTS_METHOD); final InputStream fileContents = (InputStream) getFileContents.invoke(s3File); s3Bytes = IOUtils.toByteArray(fileContents); } if (s3Bytes == null || isS3DualRetrieveEnabled()) { try { fsBytes = super.findAttachedFile(attachment); } catch (FileNotFoundException e) { LOG.info("file not found at path " + attachment.getFileLoc()); } } if (s3Bytes != null && fsBytes != null) { final String s3MD5 = DigestUtils.md5Hex(s3Bytes); final String dbMD5 = DigestUtils.md5Hex(fsBytes); if (!Objects.equals(s3MD5, dbMD5)) { LOG.error("S3 data MD5: " + s3MD5 + " does not equal FS data MD5: " + dbMD5 + " for id: " + attachment.getFileDataId()); } } return s3Bytes != null ? s3Bytes : fsBytes; } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | IOException e) { throw new RuntimeException(e); } }
From source file:com.googlecode.download.maven.plugin.internal.DownloadCache.java
public void install(String url, File outputFile, String md5, String sha1, String sha512) throws Exception { if (md5 == null) { md5 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("MD5")); }//from w w w. j a va2 s . co m if (sha1 == null) { sha1 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("SHA1")); } if (sha512 == null) { sha512 = SignatureUtils.computeSignatureAsString(outputFile, MessageDigest.getInstance("SHA-512")); } CachedFileEntry entry = getEntry(url, md5, sha1, sha512); if (entry != null) { return; // entry already here } entry = new CachedFileEntry(); entry.fileName = outputFile.getName() + '_' + DigestUtils.md5Hex(url); Files.copy(outputFile.toPath(), new File(this.basedir, entry.fileName).toPath(), StandardCopyOption.REPLACE_EXISTING); // update index loadIndex(); this.index.put(url, entry); saveIndex(); }
From source file:io.jeffrey.web.assemble.InMemoryAssembler.java
public void assemble(PutTarget target) throws Exception { for (MergeStep step : merge) { FileInputStream input = new FileInputStream(step.source); try {//ww w .j a v a 2s.c o m target.upload(step.key, step.md5, step.contentType, input, step.length); } finally { input.close(); } } for (String url : html.keySet()) { byte[] value = html.get(url).getBytes("UTF-8"); target.upload(url, DigestUtils.md5Hex(value), "text/html", new ByteArrayInputStream(value), value.length); } }
From source file:com.talis.storage.s3.cache.MemcachedChunkHandler.java
private String getMemcacheKey(String key) { return DigestUtils.md5Hex(getBucketname() + "/" + key); }
From source file:domain.security.User.java
/** * Control function used to encrypt/* ww w . j ava 2s . co m*/ * the password value prior to its persistence * to the database. */ @PrePersist @PreUpdate private void EncryptPassword() { String _encryptedPassword = DigestUtils.md5Hex(this.password); this.password = _encryptedPassword; }
From source file:net.emphased.vkclient.VkApi.java
public static String makeSignature(String viewerId, String appSecret, SortedMap<String, String> params) { StringBuilder str = new StringBuilder(); str.append(viewerId);//from ww w. ja va 2 s. c om for (Entry<String, String> param : params.entrySet()) { str.append(param.getKey()).append('=').append(param.getValue()); } str.append(appSecret); try { return DigestUtils.md5Hex(str.toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { return null; } }
From source file:com.wallellen.wechat.common.util.crypto.WxCryptUtil.java
/** * ???(?:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_3) * * @param packageParams ?/*from w w w. j a v a2s . c o m*/ * @param signKey Key(? Key) * @return ?? */ public static String createSign(Map<String, String> packageParams, String signKey) { SortedMap<String, String> sortedMap = new TreeMap<>(); sortedMap.putAll(packageParams); List<String> keys = new ArrayList<>(packageParams.keySet()); Collections.sort(keys); StringBuffer toSign = new StringBuffer(); for (String key : keys) { String value = packageParams.get(key); if (null != value && !"".equals(value) && !"sign".equals(key) && !"key".equals(key)) { toSign.append(key + "=" + value + "&"); } } toSign.append("key=" + signKey); String sign = DigestUtils.md5Hex(toSign.toString()).toUpperCase(); return sign; }
From source file:com.hadoopvietnam.action.execution.CreatePersonExecution.java
/** * Add person to the system.//from w w w .j a v a2s. c om * * @param inActionContext The action context * * @return true on success. */ @Override public Serializable execute(final TaskHandlerActionContext<ActionContext> inActionContext) { Gson gson = new Gson(); String sRequest = inActionContext.getActionContext().getParams().toString(); CreatePersonRequest createRequest = gson.fromJson(sRequest, CreatePersonRequest.class); AccountDomain inPerson = createRequest.getPerson(); Date timestamp = new Date();//DateUtils.addDays(new Date(), 7); inPerson.setExpirationDate(timestamp); String code = inPerson.getId() + " " + inPerson.getEmail() + " " + timestamp.getTime(); String accessKey = new String(Base64.encodeBase64(crypto.encrypt((code).getBytes()))); inPerson.setActiveKey(accessKey); logger.info("Save account " + inPerson.getUsername() + " to database"); if (accountService.save(inPerson)) // Send email notification if necessary { if (createRequest.getSendEmail() && sendWelcomeEmailAction != null && !sendWelcomeEmailAction.isEmpty()) { UserActionRequest request = new UserActionRequest(); request.setActionKey(sendWelcomeEmailAction); String activeLink = "http://mangtuyendung.vn/thanh-vien/kich-hoat-tai-khoan?key=" + accessKey + "&sign=" + DigestUtils.md5Hex(code); SendWelcomeEmailRequest sendWelcomeEmailRequest = new SendWelcomeEmailRequest(inPerson.getEmail(), inPerson.getUsername(), activeLink); request.setParams(gson.toJson(sendWelcomeEmailRequest)); inActionContext.getUserActionRequests().add(request); } } return inPerson; }