无法转换类型&System; System.Char []'到' System.byte []'用HMACSHA1

时间:2014-10-15 01:58:42

标签: c# windows-phone-8 unity3d

我在C#中使用这段简单的代码创建了一个Unity项目:

System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();       
byte[] keyBytes = encoding.GetBytes(Manager.Instance.Configuration.ClientSecretKey);
HMACSHA1 hmacsha1 = new HMACSHA1(keyBytes);

它适用于所有平台:Unity Editor,Android,iPhone,... 但不是在Windows Phone上!以下是异常的屏幕截图。

enter image description here

我不明白为什么会发生这种情况,因为keyBytes显然是一个byte []对象......

1 个答案:

答案 0 :(得分:2)

你是如何使用System.Text.ASCIIEncoding的?

请尝试System.Text.UTF8Encoding

System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();

MSDN Forum Regarding System.Text.ASCIIEncoding