diff --git a/server/Libraries/Kneesocks/Connection.cs b/server/Libraries/Kneesocks/Connection.cs
index afd1aa6..11e7baf 100644
--- a/server/Libraries/Kneesocks/Connection.cs
+++ b/server/Libraries/Kneesocks/Connection.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
+using Square;
namespace Kneesocks {
public class Connection {
diff --git a/server/Libraries/Kneesocks/Frame.cs b/server/Libraries/Kneesocks/Frame.cs
index c05d97a..aea0387 100644
--- a/server/Libraries/Kneesocks/Frame.cs
+++ b/server/Libraries/Kneesocks/Frame.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Square;
namespace Kneesocks {
public class Frame {
diff --git a/server/Libraries/Kneesocks/Handshake.cs b/server/Libraries/Kneesocks/Handshake.cs
index b6cb636..35871ba 100644
--- a/server/Libraries/Kneesocks/Handshake.cs
+++ b/server/Libraries/Kneesocks/Handshake.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Square;
namespace Kneesocks {
public class Handshake {
@@ -84,9 +85,7 @@ namespace Kneesocks {
public static Handshake AcceptRequest(Handshake request) {
const string nonce = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
var key = request.GetHeader("Sec-WebSocket-Key");
- var connectionHash = (key + nonce).SHA1().Base64Encode(false);
-
- var test = ("dGhlIHNhbXBsZSBub25jZQ==" + nonce).SHA1().Base64Encode(false);
+ var connectionHash = (key + nonce).SHA1().Base64Encode();
var shake = new Handshake(kStatusCode.Switching_Protocols);
shake.SetHeader("Upgrade", "websocket")
diff --git a/server/Libraries/Kneesocks/Kneesocks.csproj b/server/Libraries/Kneesocks/Kneesocks.csproj
index d37edf7..0a5bc5b 100644
--- a/server/Libraries/Kneesocks/Kneesocks.csproj
+++ b/server/Libraries/Kneesocks/Kneesocks.csproj
@@ -48,7 +48,6 @@
-
diff --git a/server/Libraries/Kneesocks/Utilities.cs b/server/Libraries/Kneesocks/Utilities.cs
deleted file mode 100644
index d44a137..0000000
--- a/server/Libraries/Kneesocks/Utilities.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Kneesocks {
- public static class StringExtensions {
- }
-
- public static class ByteArrayExtensions {
-
-
- }
-
- public static class CryptoExtensions {
- }
-}
diff --git a/server/Libraries/Square/ByteArrayExtensions.cs b/server/Libraries/Square/ByteArrayExtensions.cs
index d1126b4..91b0afc 100644
--- a/server/Libraries/Square/ByteArrayExtensions.cs
+++ b/server/Libraries/Square/ByteArrayExtensions.cs
@@ -9,5 +9,9 @@ namespace Square {
public static string Base64Encode(this byte[] bytes) {
return Convert.ToBase64String(bytes);
}
+
+ public static string ToHexString(this byte[] bytes) {
+ return BitConverter.ToString(bytes).Replace("-", "");
+ }
}
}
diff --git a/server/Libraries/Square/CryptoExtensions.cs b/server/Libraries/Square/CryptoExtensions.cs
index 0b8f1de..c149d1d 100644
--- a/server/Libraries/Square/CryptoExtensions.cs
+++ b/server/Libraries/Square/CryptoExtensions.cs
@@ -7,38 +7,36 @@ using System.Threading.Tasks;
namespace Square {
public static class CryptoExtensions {
- public enum kHashReturnType {
- RAW, HEX, BASE64
+ public static byte[] SHA1(this string str) {
+ return Encoding.UTF8.GetBytes(str).SHA1();
}
- public static string SHA1(this string str, kHashReturnType type = kHashReturnType.RAW) {
+ public static byte[] SHA1(this byte[] bytes) {
using(var hasher = new SHA1CryptoServiceProvider()) {
- return ParseRawHash(
- hasher.ComputeHash(str.GetBytes(false)),
- type
- );
+ return hasher.ComputeHash(bytes);
}
}
- public static string MD5(this string str, kHashReturnType type = kHashReturnType.RAW) {
+ public static byte[] MD5(this string str) {
+ return Encoding.UTF8.GetBytes(str).MD5();
+ }
+
+ public static byte[] MD5(this byte[] bytes) {
using(var hasher = new MD5CryptoServiceProvider()) {
- return ParseRawHash(
- hasher.ComputeHash(str.GetBytes(false)),
- type
- );
+ return hasher.ComputeHash(bytes);
}
}
- private static string ParseRawHash(byte[] hash, kHashReturnType type) {
+ /*private static string ParseRawHash(byte[] hash, kHashReturnType type) {
switch(type) {
case kHashReturnType.BASE64:
- return hash.Base64Encode(false);
+ return hash.Base64Encode();
case kHashReturnType.HEX:
return BitConverter.ToString(hash).Replace("-", "");
case kHashReturnType.RAW:
default:
return hash;
}
- }
+ }*/
}
}