我正在使用C#中的Rijndael256加密和解密方法,但是看起来我的加密方法“正在工作”;我的decrypt方法随机返回一个关于我要解密的IV或数据的错误,声明“Base-64 char数组或字符串的长度无效”。解密将工作一次或两次然后错误。我猜这与随机生成的IV大小或简单的东西有关,但任何指导都会很棒。
private string decryptData(string encData, string encIV)
{
byte[] encKey = ASCIIEncoding.UTF8.GetBytes("pemgail9uzpgzl88");
string returnValue = Convert.ToBase64String(encKey);
byte[] myIv = Convert.FromBase64String(encIV);
byte[] myMessage = ASCIIEncoding.UTF8.GetBytes(encData);
Rijndael aes = Rijndael.Create();
aes.KeySize = 256;
aes.BlockSize = 256;
aes.IV = myIv;
aes.Mode = CipherMode.CBC;
aes.Padding = PaddingMode.PKCS7;
aes.Key = encKey;
ICryptoTransform crypto = aes.CreateDecryptor(aes.Key, aes.IV);
byte[] txt = Convert.FromBase64String(encData);
byte[] cipherText = crypto.TransformFinalBlock(txt, 0, txt.Length);
return Encoding.UTF8.GetString(cipherText);
}
我的解密方法:
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["data"] != null && Request.QueryString["iv"] != null)
{
string test = decryptData(Request.QueryString["data"], Request.QueryString["iv"]);
Response.Write(test);
}
else
{
string test = encryptData("BrassMonkey");
Response.Redirect("Rijindael.aspx?data=" + test);
}
}
作为测试,我正在加密数据,将测试页重定向到自身,然后将QueryStrings中的值用于解密方法。
var svg = d3.select("body")
.append("svg")
.append("g")
svg.append("g")
.attr("class", "slices");
svg.append("g")
.attr("class", "labels");
svg.append("g")
.attr("class", "lines");
var width = 560,
height = 450,
radius = Math.min(width, height) / 2;
var pie = d3.layout.pie()
.sort(null)
.value(function(d) {
return d.value;
});
var arc = d3.svg.arc()
.outerRadius(radius * 0.85)
.innerRadius(radius * 0.83);
var outerArc = d3.svg.arc()
.innerRadius(radius * 0.9)
.outerRadius(radius * 0.9);
svg.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
var key = function(d){ return d.data.label; };
var color = d3.scale.ordinal()
.domain(["Lorem ipsum", "dolor sit", "amet", "consectetur", "adipisicing"])
.range(["#98abc5", "#8a89a6", "#7b6888", "#6b486b", "#a05d56"]);
function randomData (){
var labels = color.domain();
return labels.map(function(label){
return { label: label, value: Math.random() }
});
}
console.log("randomData()", randomData());
change(randomData());
d3.select(".randomize")
.on("click", function(){
change(randomData());
});
function change(data) {
/* ------- PIE SLICES -------*/
var slice = svg.select(".slices").selectAll("path.slice")
.data(pie(data), key);
slice.enter()
.insert("path")
.style("fill", function(d) { return color(d.data.label); })
.attr("class", "slice");
slice
.transition().duration(1000)
.attrTween("d", function(d) {
this._current = this._current || d;
var interpolate = d3.interpolate(this._current, d);
this._current = interpolate(0);
return function(t) {
return arc(interpolate(t));
};
})
slice.exit()
.remove();
};