收藏
回答

.NET 小程序授权手机号解密问题?

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

最后一次编辑于  11-25
回答关注问题邀请回答
收藏

1 个回答

  • 挥霍
    挥霍
    11-26
    /// <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;
    }


    11-26
    赞同 2
    回复 1
    • 汪春兵
      汪春兵
      11-26
      已经提前解决了,还是非常感谢!!你这个是对的
      11-26
      回复
问题标签