Skip to content
This repository was archived by the owner on Feb 20, 2022. It is now read-only.

Commit a747290

Browse files
committed
First working example using new Socket lib (await not set correctly yet)
1 parent 8d797c2 commit a747290

23 files changed

+2633
-641
lines changed

unity-project/.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ ExportedObj/
2727
sysinfo.txt
2828

2929
# Unity Package Manager
30-
/UnityPackageManager/
30+
/UnityPackageManager/
31+
32+
# UWP WSA Certificates
33+
WSATestCertificate.pfx
34+
WSATestCertificate.pfx.meta

unity-project/Assets/3rd party/ConcurrentQueue.cs

Lines changed: 0 additions & 242 deletions
This file was deleted.

unity-project/Assets/Moulin/DDP/account/DdpAccount.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2525
using UnityEngine;
2626
using System;
2727
using System.Text;
28+
#if WINDOWS_UWP
29+
using Windows.Security.Cryptography;
30+
using Windows.Security.Cryptography.Core;
31+
using Windows.Storage.Streams;
32+
#else
2833
using System.Security.Cryptography;
34+
#endif
2935
using System.Collections;
3036

3137
namespace Moulin.DDP {
@@ -46,11 +52,34 @@ public DdpAccount(DdpConnection connection) {
4652
}
4753

4854
private JSONObject GetPasswordObj(string password) {
49-
string digest = BitConverter.ToString(
50-
new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(password)))
51-
.Replace("-", "").ToLower();
52-
53-
JSONObject passwordObj = JSONObject.Create();
55+
#if WINDOWS_UWP
56+
// Convert the message string to binary data.
57+
IBuffer buffUtf8Msg = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
58+
59+
// Create a HashAlgorithmProvider object.
60+
HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha256);
61+
62+
// Demonstrate how to retrieve the name of the hashing algorithm.
63+
string strAlgNameUsed = objAlgProv.AlgorithmName;
64+
65+
// Hash the message.
66+
IBuffer buffHash = objAlgProv.HashData(buffUtf8Msg);
67+
68+
// Verify that the hash length equals the length specified for the algorithm.
69+
if (buffHash.Length != objAlgProv.HashLength)
70+
{
71+
throw new Exception("There was an error creating the hash");
72+
}
73+
74+
// Convert the hash to a string (for display).
75+
string digest = CryptographicBuffer.EncodeToHexString(buffHash);
76+
#else
77+
string digest = BitConverter.ToString(
78+
new SHA256Managed().ComputeHash(Encoding.UTF8.GetBytes(password)));
79+
#endif
80+
digest = digest.Replace("-", "").ToLower();
81+
82+
JSONObject passwordObj = JSONObject.Create();
5483
passwordObj.AddField("digest", digest);
5584
passwordObj.AddField("algorithm", "sha-256");
5685

0 commit comments

Comments
 (0)