对于新的RijndaelManaged(),文档说它支持128位和最多256位的密钥.
当您实例化新的RijndaelManaged()时,它会为您创建Key和IV.
它的默认大小是128位?
我已经使用2.0框架尝试了以下代码,我得到了一个属性,但是当我在紧凑框架上尝试这个时,它总是返回一个空数组.MSDN文档说它支持,我做错了吗?
Test x = new Test();
FieldInfo field_info = x.GetType().GetField("ArrayShorts");
object[] custom_attributes = field_info.GetCustomAttributes(typeof(MarshalAsAttribute), false);
[StructLayout(LayoutKind.Sequential)]
public struct Test
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
public ushort[] ArrayShorts;
}
Run Code Online (Sandbox Code Playgroud) c# attributes compact-framework marshalling getcustomattributes
C#看起来有4种不同的对称加密算法:RijndaelManaged,DESCryptoServiceProvider,RC2CryptoServiceProvider和TripleDESCryptoServiceProvider.
我正在寻找他们之间的更多信息.主要是它们之间的差异.MSDN没有太多帮助,或者我只是累了.;)我确信每个人之间都有利弊,就像有多种做事方式的事情一样.
谢谢你的任何启示.
托尼
我正在尝试使用MVP模式,我遇到了一个设计问题.我正在开发一个具有多个UserControl的应用程序.UserControls本身彼此无关,只代表实际模型的子集.根据我的阅读,人们倾向于说每个视图应该使用一个Presenter.这似乎有道理,但如果我有30个UserControls,我真的想要30个演示者吗?另一方面,如果我有1个Presenter和1个View代表整个"应用程序"视图,那么我将拥有膨胀的View和Presenter界面.然后每个View都必须实现与它无关的方法.我的问题是,有没有更好的方法来处理多个UserControls,或者我应该为每个View创建一个Presenter?
现在,我可以让RijndaelManaged算法在打开FIPS的本地安全设置的计算机上工作的唯一方法就是禁用它.这是一台政府计算机,所以我不确定它会如何飞行.我在msdn博客网站上看过他们说他们正在开发AES FIPS兼容版本的帖子,但我似乎无法找到更多.有谁知道这可能发生的时间?
采取以下控制器操作
public ActionResult NextBySURNAME(int id, string data)
{
//code to process the data and edit the id accoringly not written yet
return RedirectToAction("Edit", new { id = id });
}
Run Code Online (Sandbox Code Playgroud)
如果我用/ Mycontroller/NextBySURNAME/12/Smith%20Simon调用它
然后它工作正常(在这种情况下编辑记录12)但是
/ myController的/ NextBySURNAME/12 /史密斯%20
给了我一个404
现在我知道在某些情况下我的问题域尾随空白是很重要的,所以我不只是想修剪它.那为什么这会破坏我的路线呢?
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}/{data}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional, data=UrlParameter.Optional } // Parameter defaults
);
Run Code Online (Sandbox Code Playgroud) 鉴于以下内容
public class Service<T> : IService<T>
{
Repository<T> _repository = new Repository<T>();
public T Get<T>(int id)
{
return _repository.Get<T>(id);
}
}
public interface IService<T>
{
T Get<T>(int id);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下警告
类型参数"T"与外部类型"Services.IService"中的类型参数同名
我不确定这个问题是什么,为什么我关心我的返回类型是否与我告诉类的类型相同.我在这里错过了什么吗?
我知道其他问题已经被问到,但到目前为止还没有提供解决方案,或者正是我的问题.
下面的类处理字符串的加密和解密,传入的密钥和向量总是相同的.
加密和解密的字符串总是数字,大多数工作但偶尔会在解密时失败(但仅在生产服务器上).我应该提到本地和生产环境都在Windows Server 2003上的IIS6中,使用该类的代码位于.ashx处理程序中.生产服务器上失败的示例是"0000232668"
错误消息是
System.Security.Cryptography.CryptographicException:填充无效,无法删除.在System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte [] inputBuffer,Int32 inputOffset,Int32 inputCount,Byte []&outputBuffer,Int32 outputOffset,PaddingMode paddingMode,Boolean fLast)
并为代码
public class Aes
{
private byte[] Key;
private byte[] Vector;
private ICryptoTransform EncryptorTransform, DecryptorTransform;
private System.Text.UTF8Encoding UTFEncoder;
public Aes(byte[] key, byte[] vector)
{
this.Key = key;
this.Vector = vector;
// our encyption method
RijndaelManaged rm = new RijndaelManaged();
rm.Padding = PaddingMode.PKCS7;
// create an encryptor and decyptor using encryption method. key and vector
EncryptorTransform = rm.CreateEncryptor(this.Key, this.Vector);
DecryptorTransform = rm.CreateDecryptor(this.Key, this.Vector);
// used to …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建以下结构:
[StructLayout(LayoutKind.Explicit, Size=14)]
public struct Message
{
[FieldOffset(0)]
public ushort X;
[FieldOffset(2)]
[MarshalAs(UnmanagedType.ByValArray, SizeConst=5)]
private ushort[] Y;
[FieldOffset(12)]
public ushort Z;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
无法从程序集中加载"消息"类型,因为它包含偏移4处的对象字段,该字段未正确对齐或由非对象字段重叠.
有谁知道为什么这会导致错误?
注意:我不能使用Pack因为我正在使用紧凑的框架.谢谢.
我创建了WCF服务并使用独立应用程序测试WCF客户端.我能够使用Internet Explorer查看此服务,也可以在Visual Studio服务引用中查看.这是错误消息.
"The content type text/html; charset=UTF-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8)."
你能不能指出可能出错的地方?
谢谢.
c# ×9
.net ×2
aes ×2
encryption ×2
alignment ×1
asp.net-mvc ×1
attributes ×1
cryptography ×1
explicit ×1
fips ×1
generics ×1
marshalling ×1
mvp ×1
oop ×1
rijndael ×1
routing ×1
security ×1
structure ×1
wcf ×1
web-services ×1