简体   繁体   English

将Java sha512crypt转换为C#

[英]converting java sha512crypt to c#

I am trying to duplicate the following JAVA code into C# but I don't think I'm doing it right o_o 我正在尝试将以下JAVA代码复制到C#中,但我认为我做的不正确o_o

(The code is taken from ftp://ftp.arlut.utexas.edu/pub/java_hashes/Sha512Crypt.java ) (代码取自ftp://ftp.arlut.utexas.edu/pub/java_hashes/Sha512Crypt.java

JAVA variables: JAVA变量:

ctx, alt_ctx = MessageDigest ctx,alt_ctx = MessageDigest

key = String (the password to hash) key =字符串(哈希密码)

salt = String (salt to add to the hash) salt =字符串(添加到哈希中的盐)

        /*                  ---JAVA---                    //
        ////////////////////////////////////////////////////
        ctx.reset();

        ctx.update(key, 0, key.length);
        ctx.update(salt, 0, salt.length);

        alt_ctx.reset();
        alt_ctx.update(key, 0, key.length);
        alt_ctx.update(salt, 0, salt.length);
        alt_ctx.update(key, 0, key.length);

        alt_result = alt_ctx.Digest();
        //////////////////////////////////////////////////*/

C# variables: C#变量:

ctx, alt_ctx = HashAlgorithm (SHA512Managed) ctx,alt_ctx = HashAlgorithm(SHA512Managed)

key and salt are same as in JAVA... 键和盐与JAVA中的相同...

 //                       --- C# EQUIV ? ---                    //
        int TESTINGINT;
        ctx = null;
        ctx = new SHA512Managed();
        ctx.TransformBlock(key, 0, key.Length, key, 0);
        ctx.TransformBlock(salt, 0, salt.Length, salt, 0);

        alt_ctx = null;
        alt_ctx = new SHA512Managed();

        alt_ctx.TransformBlock(key, 0, key.Length, key, 0);
        alt_ctx.TransformBlock(salt, 0, salt.Length, salt, 0);
        alt_ctx.TransformBlock(key, 0, key.Length, key, 0);

        alt_result = alt_ctx.TransformFinalBlock(key, 0, key.Length); //most likely wrong here

        //?????????????????????????????????????????????????????????//

Like I said, pretty sure this is wrong... Wondering if anyone knows the exact translation. 就像我说的,很确定这是错误的...想知道是否有人知道确切的翻译。

I've also been looking at http://www.obviex.com/samples/hash.aspx for some help. 我也一直在寻找http://www.obviex.com/samples/hash.aspx寻求帮助。 This however does not give me the same output and does not have any # rounds to do. 但是,这不会给我相同的输出,也没有任何#个回合可以做。

Given the word "beta" I'm trying to ultimately replicate the following (one line) 给定单词“ beta”,我试图最终复制以下内容(一行)

$6$rounds=60000$ZIFtW/dNUcD/k$O57sTkYwuRpQcgpnIdKLShfCVR7.vGzfMhvvWn7Mg8trGJsWADChhs6S5ONybnSBWHEHIQKw66a4i/YrA4y/y1 $ 6 $ rounds = 60000 $ ZIFtW / dNUcD / k $ O57sTkYwuRpQcgpnIdKLShfCVR7.vGzfMhvvWn7Mg8trGJsWADChhs6S5ONybnSBWHEHIQKw66a4i / YrA4y / y1

Thanks for your help 谢谢你的帮助

So after doing some thorough testing, I've fixed my C# to the following which seems to be the equivalent... 因此,在进行了彻底的测试之后,我将C#固定为以下代码,这似乎是等效的...

ctx = new SHA512Managed();

byte[] digestA = new byte[key.Length + salt.Length];

ctx.TransformBlock(key, 0, key.Length, digestA, 0);
ctx.TransformBlock(salt, 0, salt.Length, digestA, key.Length);

byte[] digestB = new byte[key.Length * 2 + salt.Length];

ctx.TransformBlock(key, 0, key.Length, digestB, 0);
ctx.TransformBlock(salt, 0, salt.Length, digestB, key.Length);
ctx.TransformBlock(key, 0, key.Length, digestB, key.Length + salt.Length);

alt_ctx = new SHA512Managed();

alt_result = alt_ctx.ComputeHash(digestB);  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM