Reputation: 170
Based on a combination of previous answers, I was able to resolve an issue with outputting the appropriate characters for a hash. I am still having a problem with length, as the hash i am getting is much longer than the expected one from the documentation I am following. The api documentation says to use SHA512 and has "FA35A0194E3BE7024CEFB1839CBFC922" as the example parameter, but when I run my hash tester with a simple password like "test" to get a value to pass into it I get "EE26B0DD4AF7E749AA1A8EE3C10AE9923F618980772E473F8819A5D4940E0DB27AC185F8A0E1D5F84F88BC887FD67B143732C304CC5FA9AD8E6F57F50028A8FF" - which is obviously much longer than what I need.
FYI, here is what I'm using to do this:
byte[] hashedPassword = HashAlgorithm.Create("SHA512").ComputeHash(new UTF8Encoding(false).GetBytes("test"));
Console.WriteLine(BitConverter.ToString(hashedPassword).Replace("-", ""));
Hopefully someone out there has more experience than I do (more than none) with this hash stuff. Is it normal to shrink a value like this somehow or take a certain part of it? I'm not really sure what to do from here.
Upvotes: 2
Views: 3907
Reputation: 1
I am not sure if you figured this out, but you could convert each two-byte hex char into a single-byte. It will not look like a standard hash but it will be the size that you are expecting.
Upvotes: 0
Reputation: 61
FIPS PUB 180-4 allows truncated hashes. The main reason for adding truncated versions was that SH512 is faster than SHA256 on some CPUs, hence truncating SHA512 can be a interesting option. However, the standard uses different initial values for truncated hashes. This means you can't just take an off the shelf SHA512 implementation and truncate the result.
Upvotes: 6
Reputation: 660455
You asked for a 512 bit hash. 512 bits is 64 bytes. 64 bytes written in hex is 128 characters. I'm therefore not understanding why you think something is wrong here.
which is obviously much longer than what I need.
Why is that obvious?
If it is much longer than what you need then why did you ask for a 512 bit hash in the first place?
Is it normal to shrink a value like this somehow or take a certain part of it?
Absolutely not.
I'm not really sure what to do from here.
Hire a professional who specializes in writing security software, who can write the software for you and train you in its correct maintenance. You do not know enough about writing secure software to do so successfully. Writing security systems is one of the hardest things you can do in any language; it takes years of training and experience to write a system that is actually secure against attack.
Upvotes: 24