111,126
社区成员
发帖
与我相关
我的任务
分享
[SecuritySafeCritical]
public byte[] Encrypt(byte[] rgb, bool fOAEP)
{
if (rgb == null)
{
throw new ArgumentNullException("rgb");
}
this.GetKeyPair();
byte[] o = null;
EncryptKey(this._safeKeyHandle, rgb, rgb.Length, fOAEP, JitHelpers.GetObjectHandleOnStack<byte[]>(ref o));
return o;
}
[SuppressUnmanagedCodeSecurity, SecurityCritical, DllImport("QCall", CharSet=CharSet.Unicode)]
private static extern void DecryptKey(SafeKeyHandle pKeyContext, [MarshalAs(UnmanagedType.LPArray)] byte[] pbEncryptedKey, int cbEncryptedKey, [MarshalAs(UnmanagedType.Bool)] bool fOAEP, ObjectHandleOnStack ohRetDecryptedKey);
internal static class JitHelpers
{
// Fields
internal const string QCall = "QCall";
// Methods
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries"), SecurityCritical]
internal static ObjectHandleOnStack GetObjectHandleOnStack<T>(ref T o) where T: class
{
TypedReference reference = __makeref(o);
return new ObjectHandleOnStack(reference.GetPointerOnStack());
}
//部分代码省略
}
[StructLayout(LayoutKind.Sequential)]
internal struct ObjectHandleOnStack
{
private IntPtr m_ptr;
internal ObjectHandleOnStack(IntPtr pObject)
{
this.m_ptr = pObject;
}
}
[DllImport("XXX.DLL", CharSet = CharSet.Auto)]
static extern int testBytes([MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)]byte[] bytes);