File 从.txt检索SHA-1哈希

File 从.txt检索SHA-1哈希,file,hash,io,server,sha1,File,Hash,Io,Server,Sha1,我在自己编写的服务器程序中实现了一个SHA-1哈希函数,它生成一个.txt文件,其中包含用户名-密码对,密码由各自的哈希值表示 我在从文件中检索哈希值而不损坏它们时遇到问题。所有“数组复制”类型的函数以及任何形式的字节数组移动似乎都会损坏它们。(当它们最初作为字符串读入时,它们的值是正确的 目标是在读取密码并将其输入“sha1.isEqual(byte[],byte[])”函数后获得有效密码 这是我读取密码的方法 public void getPasswords() { Strin

我在自己编写的服务器程序中实现了一个SHA-1哈希函数,它生成一个.txt文件,其中包含用户名-密码对,密码由各自的哈希值表示

我在从文件中检索哈希值而不损坏它们时遇到问题。所有“数组复制”类型的函数以及任何形式的字节数组移动似乎都会损坏它们。(当它们最初作为字符串读入时,它们的值是正确的

目标是在读取密码并将其输入“sha1.isEqual(byte[],byte[])”函数后获得有效密码

这是我读取密码的方法

public void getPasswords()
{   
    String[] splitString = null;

    BufferedReader reader = null;

    try {
        File file = new File("hash_user_pass.txt");
        reader = new BufferedReader(new FileReader(file));
        int i = 0;
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.isEmpty()) continue; 

            splitString = line.split(" ");

            //System.out.println(splitString[0]);
            //System.out.println(splitString[1]);

            usernames.add(splitString[0]);
            passwords.add(splitString[1]);

            //passwords.add(splitString[1].getBytes());
            //System.out.println("Password Bytes: " + passwords.get(i));
            i++;
        }

    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
在这里,我将它们与用户的密码进行比较

    hashed_pass = hash(password);

    if(sha1.isEqual(passwords.get(i),hashed_pass))
    {
        System.out.println("Passwords match.");
    }

如果散列存储为文件中的十六进制字符串,则需要将十六进制字符串转换为字节数组。@samgak如何在不更改其值的情况下执行此操作?每次转换时,它都认为我正在将字符串转换为字节。请参阅,现在就更有意义了。谢谢。