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

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

Introduction

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

Prototype

public static String sha512Hex(String data) 

Source Link

Usage

From source file:net.mohatu.bloocoin.miner.SubmitList.java

private void submit() {
    for (int i = 0; i < solved.size(); i++) {
        try {/*  ww  w  .ja  va2 s . co m*/
            Socket sock = new Socket(this.url, this.port);
            String result = new String();
            DataInputStream is = new DataInputStream(sock.getInputStream());
            DataOutputStream os = null;
            BufferedReader in = new BufferedReader(new InputStreamReader(is));
            solution = solved.get(i);
            hash = DigestUtils.sha512Hex(solution);

            String command = "{\"cmd\":\"check" + "\",\"winning_string\":\"" + solution
                    + "\",\"winning_hash\":\"" + hash + "\",\"addr\":\"" + Main.getAddr() + "\"}";
            os = new DataOutputStream(sock.getOutputStream());
            os.write(command.getBytes());

            String inputLine;
            while ((inputLine = in.readLine()) != null) {
                result += inputLine;
            }

            if (result.contains("\"success\": true")) {
                System.out.println("Result: Submitted");
                Main.updateStatusText(solution + " submitted", Color.blue);
                Thread gc = new Thread(new Coins());
                gc.start();
            } else if (result.contains("\"success\": false")) {
                System.out.println("Result: Failed");
                Main.updateStatusText("Submission of " + solution + " failed, already exists!", Color.red);
            }
            is.close();
            os.close();
            os.flush();
            sock.close();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red);
        } catch (IOException e) {
            e.printStackTrace();
            Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red);
        }
    }
    Thread gc = new Thread(new Coins());
    gc.start();
}

From source file:com.petalmd.armor.authentication.backend.simple.SettingsBasedAuthenticationBackend.java

@Override
public User authenticate(final com.petalmd.armor.authentication.AuthCredentials authCreds)
        throws AuthException {
    final String user = authCreds.getUsername();
    final String clearTextPassword = authCreds.getPassword() == null ? null
            : new String(authCreds.getPassword());
    authCreds.clear();/*from ww  w .java 2  s  . com*/

    String digest = settings.get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_DIGEST, null);
    final String storedPasswordOrDigest = settings
            .get(ConfigConstants.ARMOR_AUTHENTICATION_SETTINGSDB_USER + user, null);

    if (!StringUtils.isEmpty(clearTextPassword) && !StringUtils.isEmpty(storedPasswordOrDigest)) {

        String passwordOrHash = clearTextPassword;

        if (digest != null) {

            digest = digest.toLowerCase();

            switch (digest) {

            case "sha":
            case "sha1":
                passwordOrHash = DigestUtils.sha1Hex(clearTextPassword);
                break;
            case "sha256":
                passwordOrHash = DigestUtils.sha256Hex(clearTextPassword);
                break;
            case "sha384":
                passwordOrHash = DigestUtils.sha384Hex(clearTextPassword);
                break;
            case "sha512":
                passwordOrHash = DigestUtils.sha512Hex(clearTextPassword);
                break;

            default:
                passwordOrHash = DigestUtils.md5Hex(clearTextPassword);
                break;
            }

        }

        if (storedPasswordOrDigest.equals(passwordOrHash)) {
            return new User(user);
        }

    }

    throw new AuthException("No user " + user + " or wrong password (digest: "
            + (digest == null ? "plain/none" : digest) + ")");
}

From source file:io.apicurio.hub.core.editing.EditingSessionManager.java

/**
 * @see io.apicurio.hub.core.editing.IEditingSessionManager#validateSessionUuid(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
 *///from  w  w  w . j a  va  2 s .c o  m
@Override
public long validateSessionUuid(String uuid, String designId, String user, String secret) throws ServerError {
    try {
        String hash = DigestUtils.sha512Hex(SALT + user + secret);
        long contentVersion = this.storage.lookupEditingSessionUuid(uuid, designId, user, hash);
        if (this.storage.consumeEditingSessionUuid(uuid, designId, user, hash)) {
            return contentVersion;
        } else {
            throw new ServerError("Failed to connect to API editing session using UUID: " + uuid);
        }
    } catch (StorageException e) {
        throw new ServerError(e);
    }
}

From source file:com.nohowdezign.gcpmanager.printers.PrinterManager.java

private void registerPrinter(File capabilitiesFile, String printerName) throws Exception {
    InputStream inputStream = null;

    inputStream = new FileInputStream(capabilitiesFile);

    Printer printer = new Printer();
    printer.setProxy("pamarin");
    Set<String> tags = new HashSet<String>();
    tags.add("register");
    printer.setTags(tags);//w ww .  j ava 2  s .  c o m

    String capsHash = DigestUtils.sha512Hex(inputStream);
    printer.setCapsHash(capsHash);
    printer.setStatus("REGISTER");
    printer.setCapabilities(capabilitiesFile);
    printer.setDefaults(capabilitiesFile);

    RegisterPrinterResponse response = cloudPrint.registerPrinter(printer);
    if (!response.isSuccess()) {
        return;
    }
}

From source file:me.hqm.plugindev.wget.ConfirmPrompt.java

protected boolean isInputValid(ConversationContext context, String s) {
    if (Type.REGISTER.equals(type)) {
        return context.getSessionData("password").equals(s);
    } else {/*ww  w . j ava  2  s . c om*/
        return WGET.getUser((Player) context.getForWhom()).passwordHash.equals(DigestUtils.sha512Hex(s));
    }
}

From source file:de.hub.cses.ces.jsf.bean.RegistrationBean.java

/**
 *
 * @return/*  w  w w  .  j a  v  a 2  s  . co  m*/
 */
public String register() {
    if (clientFacade.exists(user.getClientname())) {
        String errorMessage = FacesContext.getCurrentInstance().getApplication()
                .getResourceBundle(FacesContext.getCurrentInstance(), "i18n_txts").getString("exists");
        // Add View Faces Message
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, errorMessage, errorMessage);
        // Add the message into context for a specific component
        FacesContext.getCurrentInstance().addMessage(username.getClientId(), message);
        return null;
    }
    String password = user.getPassword();
    user.setPassword(DigestUtils.sha512Hex(password));
    clientFacade.create(user);
    return "index?faces-redirect=true";
}

From source file:edu.jhuapl.openessence.security.OEPasswordEncoder.java

/**
 *
 * @param rawPass/*www.  ja v  a2s. c  o  m*/
 * @param encryptDetails an {@link EncryptionDetails} object
 * @return The encrypted version of the password
 * @throws DataAccessException
 */
@Override
public String encodePassword(String rawPass, Object encryptDetails) throws DataAccessException {
    if ((encryptDetails == null) || !(encryptDetails.getClass().equals(EncryptionDetails.class))) {
        return "";
    }
    String encPass = "";
    String salt = ((EncryptionDetails) encryptDetails).getSalt();
    String algorithm = ((EncryptionDetails) encryptDetails).getAlgorithm();
    if (algorithm.equals("SHA-1")) {
        log.warn("SHA-1 DEPRECATED, retained for compatibility.");
        encPass = DigestUtils.sha1Hex(salt + rawPass);
    } else if (algorithm.equals("SHA-256")) {
        log.warn("SHA-256 DEPRECATED, retained for compatibility.");
        encPass = DigestUtils.sha256Hex(salt + rawPass);
    } else if (algorithm.equals("SHA-384")) {
        log.warn("SHA-384 DEPRECATED, retained for compatibility.");
        encPass = DigestUtils.sha384Hex(salt + rawPass);
    } else if (algorithm.equals("SHA-512")) {
        log.warn("SHA-512 DEPRECATED, retained for compatibility.");
        encPass = DigestUtils.sha512Hex(salt + rawPass);
    } else if (algorithm.equals("BCrypt")) {
        encPass = BCrypt.hashpw(rawPass, salt);
    }
    return encPass;
}

From source file:me.hqm.plugindev.wget.WGET.java

public static void register(Player player, String password) {
    String passwordHash = DigestUtils.sha512Hex(password);

    WGUser user = new WGUser();
    user.minecraftId = player.getUniqueId().toString();
    user.passwordHash = passwordHash;// w  w  w .  ja  v  a2 s  .  c o m

    Db db = Db.open(DB_URL);
    db.insert(user);
    db.close();

    login(player);
}

From source file:com.twosigma.beaker.core.module.config.DefaultBeakerConfig.java

private String hash(String password) {
    return DigestUtils.sha512Hex(password + getPasswordSalt());
}

From source file:net.orzo.lib.Strings.java

/**
 *
 *//* w w w .  j a  v  a  2s  . c  o  m*/
public Object hash(String value, String algorithm) {
    if (value == null) {
        throw new RuntimeException("null value not accepted in hash() function");
    }
    switch (algorithm.toLowerCase()) {
    case "md5":
        return DigestUtils.md5Hex(value);
    case "sha1":
        return DigestUtils.sha1Hex(value);
    case "sha256":
        return DigestUtils.sha256Hex(value);
    case "sha384":
        return DigestUtils.sha384Hex(value);
    case "sha512":
        return DigestUtils.sha512Hex(value);
    default:
        throw new RuntimeException(String.format("Unknown hash function '%s'", algorithm));
    }
}