Criptografia em SHA 1

1 resposta
G

Pessoal preciso de um help de vocês, gostaria de saber se vocês tem algum metódo, na codificação SHA1 pois pelo que tô vendo o md5 já ficou pra trás

1 Resposta

G

Será que assim daria certo?

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

public class teste
{
	private static MessageDigest md = null;
    
    static 
    {
        try 
        {
            md = MessageDigest.getInstance("SHA-1");
        } 
        catch (NoSuchAlgorithmException ex) 
        {
            ex.printStackTrace();
        }
    }

    private static char[] hexCodes(byte[] text) 
    {
        char[] hexOutput = new char[text.length * 2];
        String hexString;
 
        for (int i = 0; i < text.length; i++) 
        {
            hexString = "00" + Integer.toHexString(text[i]);
            hexString.toUpperCase().getChars(hexString.length() - 2,
                                    hexString.length(), hexOutput, i * 2);
        }
        return hexOutput;
    }

  	public static String criptografar(String pwd) 
  	{
        if (md != null) 
        {
            return new String(hexCodes(md.digest(pwd.getBytes())));
        }
        return null;
    }
}
Criado 11 de agosto de 2009
Ultima resposta 11 de ago. de 2009
Respostas 1
Participantes 1