Java XML Hash sha1Hash(String s)

Here you can find the source of sha1Hash(String s)

Description

sha Hash

License

Open Source License

Declaration

public static String sha1Hash(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011, 2016 Eurotech and/or its affiliates and others
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w w . ja v a 2  s  .  c o  m
 *     Eurotech - initial API and implementation
 *
 *******************************************************************************/

import java.io.UnsupportedEncodingException;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.xml.bind.DatatypeConverter;

public class Main {
    public static String sha1Hash(String s) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest cript = MessageDigest.getInstance("SHA-1");
        cript.reset();
        cript.update(s.getBytes("UTF8"));

        byte[] encodedBytes = cript.digest();
        return DatatypeConverter.printBase64Binary(encodedBytes);
    }
}

Related

  1. hash512(byte[] data)
  2. hashPass(String plaintext)
  3. hashPassword(char[] password, String salt, String hashAlgo)
  4. hashPassword(String password)
  5. hashToString(byte[] hash)
  6. strHash(String value, String method)
  7. validatePassword(String password, String correctHash)