对于wx.getShareInfo得到的数据encryptedData和iv的解密缺少C#版本的解密,请管理员尽快的解决!!!
还有就是为啥自己写的如下的代码,执行会报错填充值无效,无法删除!!!!请大家给看看,这个如何解决???
RijndaelManaged rijndaelCipher = new RijndaelManaged();
//16进制数据转成byte类型
byte[] edata = Convert.FromBase64String(encryptedData);
rijndaelCipher.Key = Convert.FromBase64String(sessionKey);
rijndaelCipher.IV = Convert.FromBase64String(iv);
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.BlockSize = 128;
rijndaelCipher.KeySize = 256;
rijndaelCipher.Padding=PaddingMode.PKCS7;
var transform= rijndaelCipher.CreateDecryptor();
byte[] plainText = transform.TransformFinalBlock(edata, 0, edata.Length);
string jieguo = Encoding.UTF8.GetString(plainText);
网友回复:
#region 微信分享好友,得到好友OpenId和Username
[HttpGet]
public HttpResponseMessage ShareInfoAES(string appId, string sessionKey, string encryptedData, string iv)
{
#region 解密部分
RijndaelManaged rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.Padding = PaddingMode.PKCS7;
rijndaelCipher.KeySize = 128;
rijndaelCipher.BlockSize = 128;
byte[] Data = Convert.FromBase64String(encryptedData);
byte[] pwdBytes = Convert.FromBase64String(sessionKey);
byte[] keyBytes = new byte[16];
int len = pwdBytes.Length;
if (len > keyBytes.Length) len = keyBytes.Length;
System.Array.Copy(pwdBytes, keyBytes, len);
rijndaelCipher.Key = keyBytes;
rijndaelCipher.IV = Convert.FromBase64String(iv);
ICryptoTransform transform = rijndaelCipher.CreateDecryptor();
byte[] plainText = transform.TransformFinalBlock(Data, 0, Data.Length);
string jiemi = Encoding.UTF8.GetString(plainText);
#endregion
AESModel aesModel = JsonConvert.DeserializeObject<AESModel>(jiemi);
if (appId != aesModel.watermark.appid)
{
return ReturnHttpResponse("");
}
else
{
return ReturnHttpResponse(JsonConvert.SerializeObject(aesModel));
}
}
#endregion
#region 序列化的类
public class AESModel
{
/// <summary>
/// OPENID
/// </summary>
public string openId { get; set; }
/// <summary>
///昵称
/// </summary>
public string nickName { get; set; }
/// <summary>
///性别
/// </summary>
public string gender { get; set; }
/// <summary>
///城市
/// </summary>
public string city { get; set; }
/// <summary>
///省份
/// </summary>
public string province { get; set; }
/// <summary>
///地区
/// </summary>
public string country { get; set; }
/// <summary>
///URL
/// </summary>
public string avatarUrl { get; set; }
/// <summary>
///unionId
/// </summary>
public string unionId { get; set; }
/// <summary>
///水印
/// </summary>
public Watermark watermark { get; set; }
public class Watermark
{
public string appid { get; set; }
public string timestamp { get; set; }
}
}
#endregion