简体   繁体   English

CKR_BUFFER_TOO_SMALL = 0x00000150

[英]CKR_BUFFER_TOO_SMALL = 0x00000150

I want to PInvoke C_Encrypt() "pkcs#11" from a .dll : 我想从.dll PInvoke C_Encrypt()“ pkcs#11”:

[DllImport("cryptoki.dll", SetLastError = true)]
private static extern UInt32 C_Encrypt(CK_SESSION_HANDLE hSession,IntPtr pData,CK_ULONG ulDataLen,out IntPtr pEncryptedData,out CK_ULONG pulEncryptedData);

/*
.... Main
in which I initialize the encryption parametrs with C_EncyptInit
*/ 
CK_BYTE[] text = new CK_BYTE[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x08, 0x09 };

System.UInt32 t, tt = (System.UInt32)text.Length;
IntPtr pdata = Marshal.AllocHGlobal(text.Length);
Marshal.Copy(text, 0, pdata, text.Length);

IntPtr chif = IntPtr.Zero;
tt = (System.UInt32)Marshal.SizeOf(pdata);
rv = C_Encrypt(h, pdata, tt, out chif, out t);

help please 请帮助

There's a variety of different problems here. 这里有各种各样的问题。

  1. Your P/Invoke signature is wrong. 您的P / Invoke签名错误。 The final two parameters are not out parameters. 最后两个参数不是out参数。 The C_Encrypt function will write the encrypted data to those parameters, but you need to allocate and pass them yourself. C_Encrypt函数会将加密的数据写入这些参数,但是您需要自己分配和传递它们。
  2. You need to allocate data for chif , and then pass the size that you allocated for chif as the final param t . 您需要为chif分配数据,然后将为chif分配的大小作为最终参数t传递。 This is the root cause of the error that you're seeing. 这是您所看到的错误的根本原因。
  3. Nit: Your variable names are confusing, and you seem to have mixed up tt and t somewhere, since you assign to tt twice. Nit:您的变量名令人困惑,并且您似乎在某处混淆了ttt ,因为您两次分配了tt

I resolved the problem By my self: 我自己解决了这个问题:

  [DllImport("D:/Program Files/Eracom/ProtectToolkit C SDK/bin/sw/cryptoki.dll", SetLastError = true)]
        private static extern UInt32 C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE[] pData, CK_ULONG ulDataLen, CK_BYTE[] pEncryptedData,ref CK_ULONG pulEncryptedData);

enjoy 请享用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .netcore Web 应用程序因“提供给函数的缓冲区太小”错误而失败 - .netcore web application failing with 'buffer supplied to a function was too small' error c#webservice调用,缓冲区太小(异步?) - c# webservice call, buffer too small (Async?) EasyHook-CRT调试声明失败-“缓冲区太小” - EasyHook - CRT Debug Assertion Failed - “Buffer too small” LibVLCSharp MediaInput - 缓冲区太小,将所有读取的文件保存在里面 - LibVLCSharp MediaInput - buffer to small too hold all readed file inside Oracle Data Access ORA-06512:字符串缓冲区太小 - Oracle Data Access ORA-06512: character string buffer too small PL/SQL:数字或值错误:字符串缓冲区太小 - 应用程序远程发布 - PL/SQL: numeric or value error: character string buffer too small - app remotely published 使用C#调用Oracle函数时出现字符串缓冲区太小错误 - Character string buffer too small error while calling Oracle function using C# ORA-06502:PL / SQL:数字或值错误:C#代码中的字符串缓冲区太小异常 - ORA-06502: PL/SQL: numeric or value error: character string buffer too small exception from C# code 在 Web 应用程序中从 C# 代码调用存储过程返回 PL/SQL:数字或值错误:字符串缓冲区太小 - Calling stored procedure from C# code in web application returns PL/SQL: numeric or value error: character string buffer too small C# BinaryReader.ReadChar 在读取 NetworkStream 时抛出“System.ArgumentException: The output char buffer is too small” - C# BinaryReader.ReadChar throws “System.ArgumentException: The output char buffer is too small” when reading NetworkStream
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM