@@ -25,7 +25,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25
25
using UnityEngine ;
26
26
using System ;
27
27
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
28
33
using System . Security . Cryptography ;
34
+ #endif
29
35
using System . Collections ;
30
36
31
37
namespace Moulin . DDP {
@@ -46,11 +52,34 @@ public DdpAccount(DdpConnection connection) {
46
52
}
47
53
48
54
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 ( ) ;
54
83
passwordObj . AddField ( "digest" , digest ) ;
55
84
passwordObj . AddField ( "algorithm" , "sha-256" ) ;
56
85
0 commit comments