Windows CryptAcquireContext API失败,错误代码为127

时间:2019-06-22 17:43:45

标签: windows api cryptography vb6 citrix

错误127是“ ERROR_PROC_NOT_FOUND”(“找不到指定的过程”)。

我正在运行带有Citrix XenApp和远程桌面服务的Windows Server 2016。 CryptAcquireContext API在advapi32.dll中。我在其上运行了Microsoft的Depends32.exe,并且DLL文件中的函数CryptAcquireContextA和CryptAcquireContextW绝对是 。所有的加密api函数似乎都发生了相同的错误。我测试了CryptDestroyHash,它还返回了127错误(ERROR_PROC_NOT_FOUND)。

这是我的C ++代码:

    HCRYPTPROV hProv = 0;
    BOOL bCryptAcquireContext = CryptAcquireContext(&hProv, NULL, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, 0);
    dwError = GetLastError();

此C ++在EXE中有效,但是如果将相同的代码放入从VB6调用的DLL中,则它将无效。就像所有vb6应用程序都被这些API阻止一样?

这是VB6代码:

Private Declare Function CryptAcquireContext Lib "advapi32.dll" Alias "CryptAcquireContextA" (ByRef phProv As Long, ByVal pszContainer As String, ByVal pszProvider As String, ByVal dwProvType As Long, ByVal dwFlags As Long) As Long
Private Sub Form_Load()
    Dim sProvider As String
    Dim rv as Long
    Dim sContainer As String
    Dim m_lProvider As Long
    Const PROV_RSA_FULL = 1
    Const CRYPT_VERIFYCONTEXT  As Long = &HF0000000
    Const MS_DEF_PROV As String = "Microsoft Base Cryptographic Provider v1.0"
    sProvider = MS_DEF_PROV & vbNullChar
    sContainer = vbNullChar
    rv = CryptAcquireContext(m_lProvider, 0, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)
    dwError = Err.LastDllError

    If rv = 0 and dwError <> 127 Then
        rv = CryptAcquireContext(m_lProvider, 0&, ByVal sProvider, PROV_RSA_FULL, CRYPT_NEWKEYSET)
    End If
End Sub

2 个答案:

答案 0 :(得分:0)

您要将Long传递给您定义为字符串的参数(pszContainer):

Private Declare Function CryptAcquireContext Lib "advapi32.dll" _
   Alias "CryptAcquireContextA" _
   (ByRef phProv As Long, ByVal pszContainer As String, _
   ByVal pszProvider As String, ByVal dwProvType As Long, _
   ByVal dwFlags As Long) As Long

rv = CryptAcquireContext(m_lProvider, 0, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)

改为尝试此操作(也用于CryptAcquireContext的第二次调用):

rv = CryptAcquireContext(m_lProvider, vbNullString, MS_ENH_RSA_AES_PROV, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)

答案 1 :(得分:0)

我可以说我在客户计算机上观察到了类似的问题(错误代码127-ERROR_PROC_NOT_FOUND-由CryptAcquireContextA Windows API函数设置)。谷歌搜索使我进入http://tracker.firebirdsql.org/browse/CORE-6154页面,其中讨论了相同的问题。该页面说,此问题“已解决,并使用Windows Update更新Windows Server 2016”。与我合作的客户报告说,安装Windows更新后该问题消失了。