- 解密encryptedData
以下C#代码是解密 API wx.getUserInfo 返回的encryptedData ,但是会出现持续性的解密出来是一串乱码,如解密成功了,持续的全部解密成功, 直到下次有解密失败的,又持续的解密失败。大伙有没有更好的办法吗? private static byte[] AES_decrypt(string input, string iv, string key) { RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 128; aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; aes.Key = Convert.FromBase64String(key); aes.IV = Convert.FromBase64String(iv); var decrypt = aes.CreateDecryptor(aes.Key, aes.IV); byte[] xBuff = null; using (var ms = new MemoryStream()) { using (var cs = new CryptoStream(ms, decrypt, CryptoStreamMode.Write)) { byte[] xXml = Convert.FromBase64String(input); byte[] msg = new byte[xXml.Length + 32 - xXml.Length % 32]; Array.Copy(xXml, msg, xXml.Length); cs.Write(xXml, 0, xXml.Length); } xBuff = decode2(ms.ToArray()); } return xBuff; } private static byte[] decode2(byte[] decrypted) { int pad = (int)decrypted[decrypted.Length - 1]; if (pad < 1 || pad > 32) { pad = 0; } byte[] res = new byte[decrypted.Length - pad]; Array.Copy(decrypted, 0, res, 0, decrypted.Length - pad); return res; }
2018-04-26 - 小程序解密手机号 encryptedData 乱码,python AES解密乱码怎么办?
小程序解密手机号 encryptedData 乱码,python AES解密乱码怎么办?[图片] 上面有乱码之后,会报一个json的错,
2021-04-15