Missing SHA1 HashAlgorithm

it was so easy with .netmf

using (HashAlgorithm csp = new HashAlgorithm(HashAlgorithmType.SHA1))
{
byte temp = csp.ComputeHash((key + “258EAFA5-E914-47DA-95CA-C5AB0DC85B11”).GetBytes());
accept = System.Convert.ToBase64String(temp);
}

:disappointed:

Why not use md5
https://docs.ghielectronics.com/software/tinyclr/tutorials/hashing.html

because its a technical requirement to use SHA1 and not MD5

Like what? SHA1 is old and not recommended. We need good reasons.

its a “must”

https://tools.ietf.org/html/rfc6455

without sha1 no websocket protocol

1 Like

Does this mean we give you sha1 and we get web sockets in return? :grin:

yes thats the case

1 Like
1 Like

Yes, but at one or two orders of magnitude of speed difference… If I had to do this, I would do it as a native plug-in. Not necessarily baked into the base firmware, but something in a module.

Isn’t this only needed for authentication but not for data flow?

SHA is also used for payload signing. SHA is part of the basic table stakes sign/encrypt functionality

2 Likes

RFC 3174 US Secure Hash Algorithm 1 (SHA1)
includes sample code written in c, easier for you to add to your libs…

unfortunately i am not enough familiar with c to convert this to c#


if you delete all the samples c# sha1 using System.Security.Cryptography the internet would have petabytes more free space

1 Like

I used this in the past for web sockets

3 Likes

that was quick!

here’s a piece of code… it seems to made in 2015 :wink:

   private string GetHyBi09Code(string keyValue)
    {

#if !MF_FRAMEWORK_VERSION_V4_2 && !MF_FRAMEWORK_VERSION_V4_3
//Thread.Sleep(2000);
#endif
var sha1 = new SHA1();
string tmp = sha1.MessageHash(keyValue.Trim() + “258EAFA5-E914-47DA-95CA-C5AB0DC85B11”);

        var ba = new byte[tmp.Length >> 1];
        int target = 0;
        for (int i = 0; i < tmp.Length; i += 2)
        {
            ba[target++] = tmp.Substring(i, 2).HexByteString2Byte();
        }

#if MF_FRAMEWORK_VERSION_V4_2 || MF_FRAMEWORK_VERSION_V4_3
return Convert.ToBase64String(ba).ReplaceChar(‘!’, ‘+’).ReplaceChar(‘*’ ,‘/’); // 2015-01-18 .NETMF workaround…
#else
return Convert.ToBase64String(ba);
#endif
}

1 Like

6 Likes

That smells like success.