.NET 小程序授权手机号解密问题?
发布于 7 年前 作者 mali 5004 次浏览 来自 官方Issues

从官方文档中,下载到了手机号解密的demo,只有C++,Node,Php,Python的代码,我需要.net的示例代码,请提供一下

1 回复
/// <summary>
/// 微信小程序解密用户数据
/// </summary>
/// <param name="AesIV">iv</param>
/// <param name="AesKey">session_key</param>
/// <param name="inputdata">encryptedData</param>
public static JObject decodeUser(string AesIV, string AesKey, string inputdata)
{
    JObject jo = new JObject();
    try
    {
        AesIV = AesIV.Replace(" ", "+");
        AesKey = AesKey.Replace(" ", "+");
        inputdata = inputdata.Replace(" ", "+");
        byte[] encryptedData = Convert.FromBase64String(inputdata);
 
        RijndaelManaged rijndaelCipher = new RijndaelManaged();
        rijndaelCipher.Key = Convert.FromBase64String(AesKey); // Encoding.UTF8.GetBytes(AesKey);
        rijndaelCipher.IV = Convert.FromBase64String(AesIV);// Encoding.UTF8.GetBytes(AesIV);
        rijndaelCipher.Mode = CipherMode.CBC;
        rijndaelCipher.Padding = PaddingMode.PKCS7;
        ICryptoTransform transform = rijndaelCipher.CreateDecryptor();
        byte[] plainText = transform.TransformFinalBlock(encryptedData, 0, encryptedData.Length);
        string result = Encoding.UTF8.GetString(plainText);            
        jo = JsonConvert.DeserializeObject<JObject>(result);
        jo["code"] = "200";
    }
    catch (Exception e)
    {
        jo["code"] = "500";
        jo["msg"] = e.Message;
    }
    return jo;
}
回到顶部