English 中文(简体)
证书友好化名称
原标题:Certificate Friendly Name

我试图在证书上设置友好姓名,因为我用以下代码将证书存放在一台机器上:

CRYPT_DATA_BLOB fName = {_tcslen(FriendlyName) * sizeof(TCHAR), FriendlyName};
CertSetCertificateContextProperty(certContext, CERT_FRIENDLY_NAME_PROP_ID, 0, &fName));

当友好名称是一个指向友好名称和 CentContext 的 LPWSTR 时, 显然友好名称是一个指向友好名称和 CertContext 的 LPWSTR 是保存仓库证书的有效证书背景。 函数工作正确, 名称被写入证书中。 但是, 当我在证书 shun- in 中看到它时, 名称的最后字母被短写了 。 我尝试过在名称长度上添加一个字, 最后将名称剪切成两半。 我检查了友好名称和长度以确保它们正确和正确。 如果我将友好名称改成 LPSTR, 它会显示为 Kanjii 字符 。 在微软提供的示例中, 它们会做以下操作 :

BYTE *pName = (BYTE *)"Temp Name.";
CRYPT_DATA_BLOB  Friendly_Name_Blob={32,pName};

我不知道他们从哪弄来的32个,他们也没有提供我可以找到的解释。当我用32个时,它再次删除了名字。知道我做错了什么以及如何纠正它吗?

问题回答

设置 CERT_FRIENDLY_NAME_PROP_ID 属性需要先初始化 CRYPT_DATA_BLOB ,然后使用它作为 CertSetSetCificationCtext property 的最后参数。

LPWSTR pszFriendlyName = L"My test friendly name";
CRYPT_DATA_BLOB cryptBlob;
BOOL bResult;

cryptBlob.cbData = (lstrlenW(pszFriendlyName) + 1)*sizeof(WCHAR);
cryptBlob.pbData = (PBYTE)pszFriendlyName;

// pCertContext should be set before
bResult = CertSetCertificateContextProperty (pCertContext,
                                             CERT_FRIENDLY_NAME_PROP_ID,
                                             0, (LPVOID)&cryptBlob);
if (!bResult) {
    // error
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签