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);
}
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);
}
because its a technical requirement to use SHA1 and not MD5
Like what? SHA1 is old and not recommended. We need good reasons.
Does this mean we give you sha1 and we get web sockets in return?
yes thats the case
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
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
I used this in the past for web sockets
that was quick!
here’s a piece of code… it seems to made in 2015
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
}
That smells like success.