typedef struct {
unsigned long ek[32];
unsigned long dk[32];
} des_ctx;EXPORT void des_dec(des_ctx *dc,unsigned char *data,int blocks);
EXPORT void des_enc(des_ctx *dc,unsigned char *data,int blocks);
EXPORT void des_key(des_ctx *dc,unsigned char *key);在C# 下该如何调用?
先到先得!
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential,Pack=4)]
public struct des_ctx
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray,SizeConst=32)]
public uint[] ek;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst = 32)]
public uint[] dk;
} [System.Runtime.InteropServices.DllImport("你要调用的dll名称", ExactSpelling = true)]
public static extern void des_dec(ref des_ctx dc, sbyte[] data, int blocks); [System.Runtime.InteropServices.DllImport("你要调用的dll名称", ExactSpelling = true)]
public static extern void des_enc(ref des_ctx dc, sbyte[] data, int blocks); [System.Runtime.InteropServices.DllImport("你要调用的dll名称", ExactSpelling = true)]
public static extern void des_key(ref des_ctx dc, sbyte[] data);
public struct des_ctx
{
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.SysUInt, SizeConst = 32)]
public UInt32[] ek;
[MarshalAs(UnmanagedType.ByValArray, ArraySubType = UnmanagedType.SysUInt, SizeConst = 32)] public UInt32[] dk;
}
[DllImport("3DES.dll")]
public static extern void des_dec(ref des_ctx dc, [MarshalAs(UnmanagedType.LPArray)]byte[] data, int blocks);
[DllImport("3DES.dll")]
public static extern void des_enc(ref des_ctx dc, [MarshalAs(UnmanagedType.LPArray)]byte[] data, int blocks);
[DllImport("3DES.dll")]
public static extern void des_key(ref des_ctx dc, [MarshalAs(UnmanagedType.LPArray)]byte[] key);