微信小程序解密

时间:2024-11-27 11:36:38

获取OpenId和SessionKey

private string GetOpenIdAndSessionKeyString(string code)
{
string wxUrl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + CommonData.WxAppId + "&secret=" + CommonData.WxAppSecret + "&js_code=" + code + "&grant_type=authorization_code";
return GetResponse(wxUrl);
}

code

public static string AESDecrypt(string text)
{
try
{ //判断是否是16位 如果不够补0
//text = tests(text);
//16进制数据转换成byte
byte[] encryptedData =Convert.FromBase64String(text); // strToToHexByte(text);
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, , encryptedData.Length);
string result = Encoding.UTF8.GetString(plainText);//UTF8防止乱码
//int index = result.LastIndexOf('>');
//result = result.Remove(index + 1);
return result;
}
catch (Exception ex)
{
return null; }
}