Ceci est la fonction de libeay32.dll (openssl project):C non signé `char ** out` à C#` octet [] `
int i2o_ECPublicKey (EC_KEY * key, unsigned char ** out)
Comment décrire en C# (si je veux obtenir un octet [])?
code:
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int i2o_ECPublicKey (IntPtr encKey, StringBuilder outPar);
Je n'aime pas, parce que je pense que le résultat est unicode.
Réponse
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public extern static int i2o_ECPublicKey(IntPtr encKey, ref IntPtr outPar);
[DllImport(DLLNAME, CallingConvention = CallingConvention.Cdecl)]
public static extern int i2o_ECPublicKey(IntPtr encKey, int outPar);
//Pass *out as null for required buffer length.
int reqLen = i2o_ECPublicKey(k, 0);
Byte[] outBuf = new Byte[reqLen];
IntPtr unmanagedOut = Marshal.AllocCoTaskMem(outBuf.Length);
int res = i2o_ECPublicKey(k, ref unmanagedOut);
if (res == reqLen)
{
unmanagedOut -= reqLen; // because i2o_ECPublicKey add size to unmanagedOut
Marshal.Copy(unmanagedOut, outBuf, 0, outBuf.Length);
}
Marshal.FreeCoTaskMem(unmanagedOut);