Using CryptUIWizDigitalSign() to sign a BLOB #422
Unanswered
AlanCordner
asked this question in
Q&A
Replies: 2 comments 14 replies
-
I'm not sure why you need the blob, and I'm not sure how to get that working, but I was able to do this with a real DER cert. using var cert = new X509Certificate2(@"C:\Temp\test.cer", "~CertPassword~");
using SafeCoTaskMemString pFile = new(@"C:\temp\application.exe");
var signInfo = new CRYPTUI_WIZ_DIGITAL_SIGN_INFO()
{
dwSize = (uint)Marshal.SizeOf(typeof(CRYPTUI_WIZ_DIGITAL_SIGN_INFO)),
dwSubjectChoice = CryptUIWizToSign.CRYPTUI_WIZ_DIGITAL_SIGN_SUBJECT_FILE,
ToSign = new () { pwszFileName = (System.IntPtr)pFile },
dwSigningCertChoice = CryptUIWizSignLoc.CRYPTUI_WIZ_DIGITAL_SIGN_CERT,
pSigningCertObject = cert.Handle,
};
CryptUIWizDigitalSign(CryptUIWizFlags.CRYPTUI_WIZ_NO_UI, default, default, signInfo, out _); |
Beta Was this translation helpful? Give feedback.
3 replies
-
I tried a variety of combinations, even pulling some similar code into C++, and could never get anything other than 0x80070057. I also did a bunch of web searching for samples without any success. |
Beta Was this translation helpful? Give feedback.
11 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have been able to successfully sign a dynamically generated executable using the CryptUIWizDigitalSign() function directly in my C# application, but what I really need to be able to do is sign a BLOB (byte array) so that I don't have to write it to disk first. So far, I have been unsuccessful in doing this. I keep getting an error 0x80070057 (Parameter is incorrect). When I saw your library contains support for this function I decided to try it. Unfortunately I am also unable to get it to work. I was hoping there would be a Unit Test that contained an example of using this function to sign a BLOB, but no such luck. I was wondering if anyone would be able to tell me what I am doing wrong?
This is my test app code:
I had previously created a post on StackOverflow with my attempt at using the CryptoUI library directly, but I have received no responses there as of yet: https://stackoverflow.com/questions/77017250/using-cryptui-library-to-sign-byte-array-in-c-sharp
Beta Was this translation helpful? Give feedback.
All reactions