fsd
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-05-09 07:22:04 -05:00
parent bea5eafbf8
commit a1d57101cb
7 changed files with 21 additions and 38 deletions

View file

@ -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 {

View file

@ -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 {

View file

@ -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")

View file

@ -48,7 +48,6 @@
<Compile Include="ReadBuffer.cs" />
<Compile Include="Server.cs" />
<Compile Include="Stack.cs" />
<Compile Include="Utilities.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Square\Square.csproj">

View file

@ -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 {
}
}

View file

@ -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("-", "");
}
}
}

View file

@ -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;
}
}
}*/
}
}