Example usage for org.apache.commons.codec.digest DigestUtils md5Hex

List of usage examples for org.apache.commons.codec.digest DigestUtils md5Hex

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils md5Hex.

Prototype

public static String md5Hex(String data) 

Source Link

Usage

From source file:kitt.site.controller.mobile.UserController.java

@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody Object login(@Client ClientInfo clientInfo,
        @RequestParam(value = "username", required = true) String username,
        @RequestParam(value = "password", required = true) String password,
        @RequestParam(value = "wxopenid", required = false) String wxopenid, BindResult result) {
    User user = userService.login(username);
    if (user != null && user.getPassword().equals(DigestUtils.md5Hex(password))) {
        if (false == (user.isIsactive())) {
            result.addError("status", "??!");
        } else {//w  ww.j  av a 2 s . c o  m
            session.login(user);
            userService.addUserLog(user, clientInfo);
            if (!StringUtils.isBlank(wxopenid)) {
                userService.updateWxopenid(wxopenid, user.getId());
            }
        }
    } else {
        result.addError("status", "???,?!");
    }
    return json(result);
}

From source file:com.esp8266.mkspiffs.ESP8266FS.java

private String getBuildFolderPath(Sketch s) {
    // first of all try the getBuildPath() function introduced with IDE 1.6.12
    // see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03
    try {/*from  w  w w.j  a  v a  2  s.c  om*/
        String buildpath = s.getBuildPath().getAbsolutePath();
        return buildpath;
    } catch (IOException er) {
        editor.statusError(er);
    } catch (Exception er) {
        try {
            File buildFolder = FileUtils.createTempFolder("build",
                    DigestUtils.md5Hex(s.getMainFilePath()) + ".tmp");
            return buildFolder.getAbsolutePath();
        } catch (IOException e) {
            editor.statusError(e);
        } catch (Exception e) {
            // Arduino 1.6.5 doesn't have FileUtils.createTempFolder
            // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
            java.lang.reflect.Method method;
            try {
                method = BaseNoGui.class.getMethod("getBuildFolder");
                File f = (File) method.invoke(null);
                return f.getAbsolutePath();
            } catch (SecurityException ex) {
                editor.statusError(ex);
            } catch (IllegalAccessException ex) {
                editor.statusError(ex);
            } catch (InvocationTargetException ex) {
                editor.statusError(ex);
            } catch (NoSuchMethodException ex) {
                editor.statusError(ex);
            }
        }
    }
    return "";
}

From source file:com.jredrain.startup.Bootstrap.java

/**
 * init start......../*  w  w  w. j  av  a  2 s  .  c  o m*/
 *
 * @throws Exception
 */
public void init() throws Exception {
    port = Integer.valueOf(Integer.parseInt(Globals.REDRAIN_PORT));
    String inputPwd = Globals.REDRAIN_PASSWORD;
    if (notEmpty(inputPwd)) {
        this.password = DigestUtils.md5Hex(inputPwd).toLowerCase();
        Globals.REDRAIN_PASSWORD_FILE.deleteOnExit();
        IOUtils.writeText(Globals.REDRAIN_PASSWORD_FILE, this.password, CHARSET);
    } else {
        if (!Globals.REDRAIN_PASSWORD_FILE.exists()) {
            this.password = DigestUtils.md5Hex(this.password).toLowerCase();
            IOUtils.writeText(Globals.REDRAIN_PASSWORD_FILE, this.password, CHARSET);
        } else {
            password = IOUtils.readText(Globals.REDRAIN_PASSWORD_FILE, CHARSET).trim().toLowerCase();
        }
    }
}

From source file:corner.payment.services.impl.processor.AlipayProcessor.java

/**
 * //from  w w  w  .ja  v a2  s.co m
 * @see corner.payment.services.PaymentProcessor#verifyReturn(java.util.Map)
 */
@Override
public boolean verifyReturn(Map<String, String> params) {
    if (params == null || params.isEmpty()) {
        throw new IllegalArgumentException("No params.");
    }
    final Map<String, String> _data = new HashMap<String, String>();
    String _sign = null;
    String _sign_type = null;
    // ?map???singsign_type,?
    for (Iterator<String> iter = params.keySet().iterator(); iter.hasNext();) {
        String name = iter.next();
        String value = params.get(name);
        if (name.equalsIgnoreCase("sign")) {
            _sign = value;
            continue;
        } else if (name.equalsIgnoreCase("sign_type")) {
            _sign_type = value;
            continue;
        }
        _data.put(name, value);
    }

    if (_sign == null || _sign_type == null) {
        // ?????,?
        return false;
    }
    if (!"MD5".equalsIgnoreCase(_sign_type)) {
        throw new UnsupportedOperationException("Not support digest type[" + _sign_type + "]");
    }
    // ??,????
    final List<String> keys = new ArrayList<String>(_data.keySet());
    Collections.sort(keys);

    final StringBuilder content = new StringBuilder();
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        String value = _data.get(key);
        content.append((i == 0 ? "" : "&") + key + "=" + value);
    }
    content.append(this.key);

    String _tocheck = "";
    if ("MD5".equalsIgnoreCase(_sign_type)) {
        try {
            _tocheck = DigestUtils.md5Hex(content.toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
    return _tocheck.equalsIgnoreCase(_sign);
}

From source file:com.hotmart.hot.uploader.rest.UploadRESTTest.java

/**
 * Test of download method, of class UploadREST.
 *//*from  w ww.  j  a va2s.c  o m*/
@Test
@InSequence(3)
// @GET @Path("v1/file/download/"+MD5)
public void testDownload(@ArquillianResteasyResource UploadREST uploadREST) throws Exception {

    Response response = uploadREST.download(MD5);
    StreamingOutput fileDownload = (StreamingOutput) response.getEntity();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    fileDownload.write(baos);
    FileUtils.writeByteArrayToFile(new File("./src/test/resources/files/download"), baos.toByteArray());
    assertThat(DigestUtils.md5Hex(baos.toByteArray())).isEqualTo(MD5);
}

From source file:com.glaf.core.util.RequestUtils.java

public static String decodeString(String str, String token) {
    try {//from ww  w.ja  v  a 2  s.c o m
        // Base64 base64 = new Base64();
        // byte[] bytes = base64.decode(StringTools.decodeHex(str));
        // String tmp = new String(bytes);
        String tmp = str;
        Encryptor cryptor = EncryptorFactory.getEncryptor();
        tmp = cryptor.decrypt(tmp);
        String salt = DigestUtils.md5Hex(token);
        tmp = StringUtils.replace(tmp, salt, "");
        return tmp;
    } catch (Exception ex) {
        return str;
    }
}

From source file:com.sonicle.webtop.core.xmpp.ChatMessage.java

public static String buildUniqueId(EntityBareJid fromUser, String fromUserResource, DateTime timestamp) {
    CompositeId cid = new CompositeId(fromUser, fromUserResource,
            new Long(timestamp.withZone(DateTimeZone.UTC).getMillis()));
    return DigestUtils.md5Hex(cid.toString());
}

From source file:com.chiorichan.terminal.commands.UpdateCommand.java

@Override
public boolean execute(AccountAttachment sender, String command, String[] args) {
    if (!AutoUpdater.instance().isEnabled()) {
        sender.sendMessage(EnumColor.RED + "I'm sorry but updates are disabled per configs!");
        return true;
    }//from   w w  w . j a v a  2s.co m

    if (AppConfig.get().getBoolean("auto-updater.console-only") && !(sender instanceof AccountAttachment)) {
        sender.sendMessage(EnumColor.RED + "I'm sorry but updates can only be performed from the console!");
        return true;
    }

    if (!testPermission(sender))
        return true;

    if (args.length > 0)
        if (args[0].equalsIgnoreCase("latest"))
            try {
                if (args.length > 1 && args[1].equalsIgnoreCase("force")) {
                    BuildArtifact latest = AutoUpdater.instance().getLatest();

                    if (latest == null)
                        sender.sendMessage(EnumColor.RED
                                + "Please review the latest version without \"force\" arg before updating.");
                    else {
                        sender.sendMessage(EnumColor.YELLOW
                                + "Please wait as we download the latest version of Chiori Web Server...");

                        // TODO Add support for class files

                        File currentJar = new File(URLDecoder.decode(
                                Loader.class.getProtectionDomain().getCodeSource().getLocation().getPath(),
                                "UTF-8"));
                        File updatedJar = new File("update.jar");

                        Download download = new Download(new URL(latest.getJar()), updatedJar.getName(),
                                updatedJar.getPath());
                        download.setListener(new DownloadProgressDisplay(sender));
                        download.run();

                        String origMD5 = new String(NetworkFunc.readUrl(latest.getMD5File())).trim();

                        if (origMD5 != null && !origMD5.isEmpty()) {
                            String descMD5 = DigestUtils.md5Hex(new FileInputStream(updatedJar.getPath()))
                                    .trim();

                            if (descMD5.equals(origMD5))
                                sender.sendMessage(EnumColor.AQUA
                                        + "SUCCESS: The downloaded jar and control MD5Checksum matched, '"
                                        + origMD5 + "'");
                            else {
                                sender.sendMessage(EnumColor.RED
                                        + "ERROR: The server said the downloaded jar should have a MD5Checksum of '"
                                        + origMD5 + "' but it had the MD5Checksum '" + descMD5
                                        + "', UPDATE ABORTED!!!");
                                FileUtils.deleteQuietly(updatedJar);
                                return true;
                            }
                        }

                        currentJar.delete();
                        FileInputStream fis = null;
                        FileOutputStream fos = null;
                        try {
                            fis = new FileInputStream(updatedJar);
                            fos = new FileOutputStream(currentJar);
                            IOUtils.copy(fis, fos);
                        } catch (IOException e) {
                            e.printStackTrace();
                        } finally {
                            IOUtils.closeQuietly(fis);
                            IOUtils.closeQuietly(fos);
                        }

                        updatedJar.setExecutable(true, true);

                        String newMD5 = DigestUtils.md5Hex(new FileInputStream(currentJar.getPath())).trim();

                        if (origMD5 != null && !origMD5.isEmpty() && newMD5.equals(origMD5)) {
                            sender.sendMessage(EnumColor.AQUA + "----- Chiori Auto Updater -----");
                            sender.sendMessage(EnumColor.AQUA
                                    + "SUCCESS: The downloaded jar was successfully installed in the place of your old one.");
                            sender.sendMessage(EnumColor.AQUA + "You will need to restart "
                                    + Versioning.getProduct() + " for the changes to take effect.");
                            sender.sendMessage(EnumColor.AQUA
                                    + "Please type 'stop' and press enter to make this happen, otherwise you may encounter unexpected problems!");
                            sender.sendMessage(EnumColor.AQUA + "----- ------------------- -----");
                        } else {
                            sender.sendMessage(EnumColor.YELLOW + "----- Chiori Auto Updater -----");
                            sender.sendMessage(EnumColor.RED
                                    + "SEVERE: There was a problem installing the downloaded jar in the place of your old one.");
                            sender.sendMessage(EnumColor.RED
                                    + "Sorry about that because most likely your current jar is now currupt");
                            sender.sendMessage(EnumColor.RED + "Try redownloading this version yourself from: "
                                    + latest.getJar());
                            sender.sendMessage(EnumColor.RED + "Details: " + latest.getHtmlUrl());
                            sender.sendMessage(EnumColor.YELLOW + "----- ------------------- -----");
                        }

                        // Disable updater until next boot.
                        AutoUpdater.instance().setEnabled(false);

                        AppController.restartApplication(
                                "The update was successfully downloaded, restarting to apply it.");
                    }
                } else {
                    sender.sendMessage(EnumColor.AQUA + "Please wait as we poll the Jenkins Build Server...");
                    AutoUpdater.instance().forceUpdate(sender);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        else
            args = new String[0];

    if (args.length == 0) {
        sender.sendMessage(EnumColor.AQUA + "Please wait as we check for updates...");
        AutoUpdater.instance().check(sender, false);
    }

    return true;
}

From source file:corner.services.payment.impl.processor.AlipayProcessor.java

/**
 * /*from w  w  w  .  j av a  2 s  .  c o m*/
 * @see corner.services.payment.PaymentProcessor#verifyReturn(java.util.Map)
 */
public boolean verifyReturn(Map<String, String> params) {
    if (params == null || params.isEmpty()) {
        throw new IllegalArgumentException("No params.");
    }
    final Map<String, String> _data = new HashMap<String, String>();
    String _sign = null;
    String _sign_type = null;
    // ?map???singsign_type,?
    for (Iterator<String> iter = params.keySet().iterator(); iter.hasNext();) {
        String name = iter.next();
        String value = params.get(name);
        if (name.equalsIgnoreCase("sign")) {
            _sign = value;
            continue;
        } else if (name.equalsIgnoreCase("sign_type")) {
            _sign_type = value;
            continue;
        }
        _data.put(name, value);
    }

    if (_sign == null || _sign_type == null) {
        // ?????,?
        return false;
    }
    if (!"MD5".equalsIgnoreCase(_sign_type)) {
        throw new UnsupportedOperationException("Not support digest type[" + _sign_type + "]");
    }
    // ??,????
    final List<String> keys = new ArrayList<String>(_data.keySet());
    Collections.sort(keys);

    final StringBuilder content = new StringBuilder();
    for (int i = 0; i < keys.size(); i++) {
        String key = keys.get(i);
        String value = _data.get(key);
        content.append((i == 0 ? "" : "&") + key + "=" + value);
    }
    content.append(this.key);

    String _tocheck = "";
    if ("MD5".equalsIgnoreCase(_sign_type)) {
        try {
            _tocheck = DigestUtils.md5Hex(content.toString().getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }
    return _tocheck.equalsIgnoreCase(_sign);
}

From source file:com.glaf.core.execution.FileExecutionHelper.java

public void save(Connection connection, String serviceKey, File file) {
    String sql = " insert into " + BlobItemDomainFactory.TABLENAME
            + " (ID_, BUSINESSKEY_, FILEID_, SERVICEKEY_, NAME_, TYPE_, FILENAME_, PATH_, LASTMODIFIED_, LOCKED_, STATUS_, DATA_, CREATEBY_, CREATEDATE_)"
            + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ";
    PreparedStatement psmt = null;
    try {//from w  w w  . j av  a 2s  . c o  m
        psmt = connection.prepareStatement(sql);
        psmt.setString(1, UUID32.getUUID());
        psmt.setString(2, serviceKey);
        psmt.setString(3, DigestUtils.md5Hex(file.getAbsolutePath()));
        psmt.setString(4, serviceKey);
        psmt.setString(5, file.getName());
        psmt.setString(6, "Execution");
        psmt.setString(7, file.getAbsolutePath());
        psmt.setString(8, file.getAbsolutePath());
        psmt.setLong(9, file.lastModified());
        psmt.setInt(10, 0);
        psmt.setInt(11, 1);
        psmt.setBytes(12, FileUtils.getBytes(file));
        psmt.setString(13, "system");
        psmt.setTimestamp(14, DateUtils.toTimestamp(new java.util.Date()));
        psmt.executeUpdate();
    } catch (Exception ex) {
        logger.error(ex);
        ex.printStackTrace();
        throw new RuntimeException(ex);
    } finally {
        JdbcUtils.close(psmt);
    }
}