Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将ASP.NET身份用户移植到Java servlet_Java_C#_Asp.net - Fatal编程技术网

如何将ASP.NET身份用户移植到Java servlet

如何将ASP.NET身份用户移植到Java servlet,java,c#,asp.net,Java,C#,Asp.net,我有一个网站,我正试图从Asp.NET移植到Java servlet,需要移植AspNetUsers表 我需要知道Asp.NET identity用来散列密码的算法,以便在Java中验证旧用户的密码并为新用户创建新的散列 我知道Asp.NET使用SHA-1算法,我可以用ApacheCommons DigestUtils类复制该算法,但我不知道Asp.NET使用的salt,因此我无法验证密码 我可以接受算法解释,但精确的代码会更好。我查看了上面提到的页面,发现Identity使用Rfc2898De

我有一个网站,我正试图从Asp.NET移植到Java servlet,需要移植AspNetUsers表

我需要知道Asp.NET identity用来散列密码的算法,以便在Java中验证旧用户的密码并为新用户创建新的散列

我知道Asp.NET使用SHA-1算法,我可以用ApacheCommons DigestUtils类复制该算法,但我不知道Asp.NET使用的salt,因此我无法验证密码


我可以接受算法解释,但精确的代码会更好。

我查看了上面提到的页面,发现Identity使用Rfc2898DeriveBytes方法生成salt。我现在可以使用 生成散列

端口代码:

public static String hashPassword(String password) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
    byte[] salt;
    byte[] buffer2;
    if (password == null)
        throw new IllegalArgumentException("password");
    Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(password,new byte[0x10],0x3e8);
    salt = bytes.getSalt();
    buffer2 = bytes.getBytes(0x20);
    byte[] dst = new byte[0x31];
    System.arraycopy(salt, 0, dst, 1, 0x10);
    System.arraycopy(buffer2, 0, dst, 0x11, 0x20);
    return Base64.encodeBase64String(dst);

}
public static boolean verifyHashedPassword(String hashedPassword, String password) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
    byte[] buffer4;
    if (hashedPassword == null)
        return false;
    if (password == null)
        throw new IllegalArgumentException("password");
    byte[] src = Base64.decodeBase64(hashedPassword);
    if ((src.length != 0x31) || (src[0] != 0))
       return false;
    byte[] dst = new byte[0x10];
    System.arraycopy(src, 1, dst, 0, 0x10);
    byte[] buffer3 = new byte[0x20];
    System.arraycopy(src, 0x11, buffer3, 0, 0x20);
    Rfc2898DeriveBytes bytes = new Rfc2898DeriveBytes(password,dst,0x3e8);
    buffer4 = bytes.getBytes(0x20);
    return Arrays.equals(buffer3, buffer4);



}

(RFC2898DeriveBytes类来自上述库)

可能有助于在下面看到我的答案。请分享您的实现,我被困在同一个地方。