我试图了解如何在XP,Vista和Windows 7中获取从PEM格式导入的公钥(下面的代码中包含的示例).示例代码将导入XP和Windows Vista/7上的密钥,但不是一样的方法.
在Windows XP上,加密提供程序的名称中需要字符串"(Prototype)",并允许调用CryptImportPublicKeyInfo进行传递.
在Windows 7上,"(Prototype)"提供程序显然存在,但不支持对CryptImportPublicKeyInfo的调用,这令人困惑.
这些操作系统之间的正确实现是什么样的?是否有必要检测XP并使用"(Prototype)"请求名称,而没有它用于其他操作系统?是否有可能在某些XP系统上仍会失败?
或者,有没有办法检测这种混乱的行为,并选择哪个加密提供商将支持必要的呼叫?
Windows 7上的输出:
ANALYZING CRYPTOGRAPHIC SUPPORT FOR:
"Microsoft Enhanced RSA and AES Cryptographic Provider"
CryptAcquireContext success.
CryptAcquireContext.1 success.
CryptStringToBinary.2 success.
CryptDecodeObjectEx success.
CryptImportPublicKeyInfo success.
SUCCESS.
ANALYZING CRYPTOGRAPHIC SUPPORT FOR:
"Microsoft Enhanced RSA and AES Cryptographic Provider (Prototype)"
CryptAcquireContext success.
CryptAcquireContext.1 success.
CryptStringToBinary.2 success.
CryptDecodeObjectEx success.
CryptImportPublicKeyInfo FAILED****.
Run Code Online (Sandbox Code Playgroud)
Windows XP上的输出:
ANALYZING CRYPTOGRAPHIC SUPPORT FOR:
"Microsoft Enhanced RSA and AES Cryptographic Provider"
CryptAcquireContext success.
CryptAcquireContext.1 success.
CryptStringToBinary.2 success. …Run Code Online (Sandbox Code Playgroud)