In the current version you should work a little with unsafe segment.
First of all you should declare your param structure:
[StructLayout(LayoutKind.Sequential)]
public struct CK_KEY_DERIVATION_STRING_DATA
{
public int len;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8)]
public byte[] data;
}
Note that I specified SizeCont=8, considering for example a DES key. If your key has different length you should specify the exact length.
Then, you should convert your structure to a byte array:
CK_KEY_DERIVATION_STRING_DATA param = new CK_KEY_DERIVATION_STRING_DATA();
param.data = new byte[]{0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10};
param.len = 8;
int len = Marshal.SizeOf(param);
IntPtr pointer = Marshal.AllocCoTaskMem(len);
Marshal.StructureToPtr(param, pointer, false);
unsafe
{
byte* p = (byte*)pointer.ToPointer();
byte[] b = new byte[len];
for (int i = 0; i < len; i++)
{
b[i] = p[i];
}
Mechanism m = new Mechanism(Mechanism.CKM_XOR_BASE_AND_DATA, b);
}