c# - Problems when P/Invoking CertCreateSelfSignCertificate -


i following this article (in there link .cs file @ bottom of page) generate self-signed x509certificate2. code in article works want extend it. trying pass optional argument, _in_opt_ pcrypt_algorithm_identifier psignaturealgorithm, certcreateselfsigncertificate.

i have created structure it:

struct cryptoapiblob {     public int32 cbdata;     public intptr pbdata; }  struct cryptalgorithmidentifier {     public string pszobjid;     public cryptoapiblob parameters; } 

the code trying use create is:

cryptalgorithmidentifier algorithm = new cryptalgorithmidentifier { pszobjid = "szoid_nist_aes256_cbc", parameters = new cryptoapiblob { cbdata = 0 } }; algorithmpointer = marshal.allochglobal(marshal.sizeof(algorithm)); marshal.structuretoptr(algorithm, algorithmpointer, false); 

i pass algorithmpointer method.

i error when try pass certcreateselfsigncertificate:

an unhandled exception of type 'system.runtime.interopservices.comexception' occurred in mscorlib.dll

additional information: asn1 bad arguments function call. (exception hresult: 0x80093109)

does happen know why happens, or can see problems way i've defined structure or allocated in memory?

as @luaan noted, strings can tricky marshal correctly in p/invoke, it's easiest avoid p/invoke interop when can. still curious going wrong here.

from msdn docs on pcrypt_algorithm_identifier looks though should pass in actual oid of algorithm "2.16.840.1.101.3.4.1.42" in case. szoid_nist_aes256_cbc in list there c/c++ identifier (or macro) expands said oid string.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -