几个小时以来,我一直在寻找将字符串加密到URL的完美方法.这是我找到的方法
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web;
public class SimplerAES
{
private static byte[] key = { 123, 217, 19, 11, 24, 26, 85, 45, 114, 184, 27, 162, 37, 112, 222, 209, 241, 24, 175, 144, 173, 53, 196, 29, 24, 26, 17, 218, 131, 236, 53, 209 };
private static byte[] vector = { 146, 64, 191, 111, 23, 3, 113, 119, 231, 121, 221, 112, 79, 32, 114, 156 };
private ICryptoTransform …Run Code Online (Sandbox Code Playgroud) 我有以下代码。当我检查变量 i 的值时,它是 16 个字节,但是当输出转换为 Base64 时,它是 24 个字节。
byte[] bytOut = ms.GetBuffer();
int i = 0;
for (i = 0; i < bytOut.Length; i++)
if (bytOut[i] == 0)
break;
// convert into Base64 so that the result can be used in xml
return System.Convert.ToBase64String(bytOut, 0, i);
Run Code Online (Sandbox Code Playgroud)
这是预期的吗?我正在尝试减少存储,这是我的问题之一。
我刚刚问了一个关于我班级的问题:
Public class Parent {
public IList<ParentDetail> ParentDetails {
get { return _ParentDetails; }
}
private List<ParentDetail> _ParentDetails = new List<ParentDetail>();
public Parent() {
this._ParentDetails = new List<ParentDetail>();
}
}
public class ParentDetail {
public int Id { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
这里的一位专家(Jon)告诉我如何按照ParentDetails.Id的顺序迭代这个类.这是他的解决方案,运作良好. 上一个问题
foreach(var details in Model.Parent.ParentDetails.OrderBy(d => d.Id))
{
// details are processed in increasing order of Id here
// what's needed is to get access to the original order
// information. Something like as follows:
// …Run Code Online (Sandbox Code Playgroud)