Encryption Url加密问题

Encryption Url加密问题,encryption,asp.net-mvc-5,Encryption,Asp.net Mvc 5,我正试图利用来自a的代码,但我一直遇到一些我不知道如何解决的错误 以下行无法执行: inputByte=Convert.FromBase64String(encryptedText) 它提供了以下错误: Base-64字符数组或字符串的长度无效 接下来,此行也无法执行 Dictionary decryptedParameters=new Dictionary() 返回的错误是: 索引超出了数组的边界 我怎样才能着手解决这个问题 类EncryptedActionParameterAttribut

我正试图利用来自a的代码,但我一直遇到一些我不知道如何解决的错误

以下行无法执行:

inputByte=Convert.FromBase64String(encryptedText)

它提供了以下错误:

Base-64字符数组或字符串的长度无效

接下来,此行也无法执行

Dictionary decryptedParameters=new Dictionary()

返回的错误是:

索引超出了数组的边界

我怎样才能着手解决这个问题


类EncryptedActionParameterAttribute:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Data.Entity;
使用System.Data.Entity.Infrastructure;
使用系统线程;
使用System.Web.Mvc;
使用WebMatrix.WebData;
使用媒介模型;
使用System.Security.Cryptography;
使用System.IO;
命名空间中介筛选器
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
公共类EncryptedActionParameterAttribute:ActionFilterAttribute
{
公共覆盖无效OnActionExecuting(ActionExecutingContext filterContext)
{
Dictionary decryptedParameters=新字典();
if(HttpContext.Current.Request.QueryString.Get(“q”)!=null)
{
string encryptedQueryString=HttpContext.Current.Request.QueryString.Get(“q”);
string DecriptedString=Decrypt(encryptedQueryString.ToString());
string[]paramsars=decreptedstring.Split(“?”);
for(int i=0;i
MyExtensions类:

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.Mvc;
使用系统文本;
使用System.Web.Routing;
使用System.Security.Cryptography;
使用System.IO;
命名空间中介模型
{
公共静态类MyExtensions
{
公共静态MVCHTMLSING EncodedActionLink(此HtmlHelper HtmlHelper、字符串链接文本、字符串操作名、字符串控制器名、对象路由值、对象htmlAttributes)
{
string queryString=string.Empty;
字符串HtmlAttributeString=string.Empty;
string AreaName=string.Empty;
if(routeValue!=null)
{
RouteValueDictionary d=新的RouteValueDictionary(routeValues);
对于(int i=0;i0)
{
queryString+=“?”;
}
queryString+=d.Keys.ElementAt(i)+“=”+d.Values.ElementAt(i);
}
}
如果(htmlAttributes!=null)
{
RouteValueDictionary d=新的RouteValueDictionary(htmlAttributes);
对于(int i=0;i
我怀疑Base64上的无效长度错误是由于从查询字符串中删除了一些“=”符号造成的

很好地解释了这一点

base64编码字符串的长度始终是4的倍数。如果不是4的倍数,则会追加=个字符,直到其为。形式为?name=value的查询字符串在值包含=个字符时出现问题(其中一些将被删除,我不记得确切的行为)。在执行base64解码之前,您可能不需要添加正确数量的=字符

就您的字典而言,您没有提供任何类型参数,