⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cppapi.c

📁 windows的加密api源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    int     ret;
    BYTE    *pbTmp;

    ret = MessageBox(NULL, "Type User Data", "CryptGetUserData", MB_OK);

    if (hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    *dwBufLen = strlen("This is a string to hash");
    if ((pbTmp = (BYTE *) malloc(*dwBufLen)) == NULL)
    {
	SetLastError(NTE_NO_MEMORY);
	return CPPAPI_FAILED;
    }

    strcpy(pbTmp, "This is a string to hash");

    *pbData = pbTmp;
#endif

    return CPPAPI_SUCCEED;

}

/*
 -  CryptConfirmSignature
 -
 *  Purpose:
 *                Determine weather the signing should proceed.
 *
 *
 *  Parameters:
 *               IN      pTmpUser     -  Pointer to the user list structure
 *               IN      dwKeySpec    -  Type of key to be used for signing
 *               IN      sDescription -  Description of document to be signed
 *
 *  Returns:
 */
BOOL CryptConfirmSignature(
                           IN PNTAGUserList pTmpUser,
                           IN DWORD dwKeySpec,
                           IN LPCTSTR sDescription
                           )
{
    DWORD   dwResult = TRUE;

#ifdef _USE_UI
    DIALOG_INFO Info;

    if (!GetDialogInfo(pTmpUser, SIGN_TXT, dwKeySpec, &Info))
        dwResult = FALSE;
    else
    {
        if (-1 == (dwResult = DialogBoxParam(hInstance,
                                             MAKEINTRESOURCE(IDD_SOLICIT_PASSWORD),
                                             pTmpUser->hWnd,
                                             (DLGPROC)DialogSolicitPassword,
                                             (long)&Info)))
            dwResult = FALSE;
    }
#endif // _USE_UI
#ifdef MESSAGEBOXES
    int     ret;

    if (pTmpUser->hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (strcmp(sDescription, "signed") != 0)
    {
	SetLastError(NTE_BAD_SIGNATURE);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptConfirmSignature", MB_OK);
#endif

    return dwResult;

}

/*
 -  CryptUserProtectKey
 -
 *  Purpose:      Obtain or determine user protection information.
 *                
 *
 *
 *  Parameters:
 *               IN      hPrivid      -  Handle to the id of the user
 *               IN      hKey         -  Handle to key
 *
 *  Returns:
 */
BOOL CryptUserProtectKey(IN HPRIVUID hUID,
                         IN HCRYPTKEY hKey)
{

#ifdef MESSAGEBOXES
    int     ret;

    if (hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (hKey == 0)
    {
	SetLastError(NTE_BAD_KEY);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptUserProtectKey", MB_OK);
#endif

    return CPPAPI_SUCCEED;

}


/*
 -  CryptConfirmEncryption
 -
 *  Purpose:
 *                Determine weather the encryption should proceed.
 *
 *
 *  Parameters:
 *               IN      hPrivid      -  Handle to the id of the user
 *               IN      hKey         -  Handle to key
 *               IN      final        -  flag indicating last encrypt for a
 *                                       block of data
 *
 *  Returns:
 */
BOOL CryptConfirmEncryption(IN HPRIVUID hUID,
                            IN HCRYPTKEY hKey,
                            IN BOOL final)
{

#ifdef MESSAGEBOXES
    int     ret;

    if (hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (hKey == 0)
    {
	SetLastError(NTE_BAD_KEY);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptConfirmEncryption", MB_OK);
#endif

    return CPPAPI_SUCCEED;

}


/*
 -  CryptConfirmDecryption
 -
 *  Purpose:
 *                Determine weather the DEcryption should proceed.
 *
 *
 *  Parameters:
 *               IN      hPrivid      -  Handle to the id of the user
 *               IN      hKey         -  Handle to key
 *               IN      final        -  flag indicating last encrypt for a
 *                                       block of data
 *
 *  Returns:
 */
BOOL CryptConfirmDecryption(IN HPRIVUID hUID,
                            IN HCRYPTKEY hKey,
                            IN BOOL final)
{
#ifdef MESSAGEBOXES
    int     ret;

    if (hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (hKey == 0)
    {
	SetLastError(NTE_BAD_KEY);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptConfirmDecryption", MB_OK);
#endif

    return CPPAPI_SUCCEED;

}


/*
 -  CryptConfirmTranslation
 -
 *  Purpose:
 *                Determine weather the translation should proceed.
 *
 *
 *  Parameters:
 *               IN      hPrivid      -  Handle to the id of the user
 *               IN      hKey         -  Handle to key
 *               IN      final        -  flag indicating last encrypt for a
 *                                       block of data
 *
 *  Returns:
 */
BOOL CryptConfirmTranslation(IN HPRIVUID hUID,
                             IN HCRYPTKEY hKey,
                             IN BOOL final)
{

#ifdef MESSAGEBOXES
    int     ret;

    if (hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (hKey == 0)
    {
	SetLastError(NTE_BAD_KEY);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptConfirmTranslation", MB_OK);
#endif

    return CPPAPI_SUCCEED;

}


/*
 -  CryptConfirmExportKey
 -
 *  Purpose:
 *                Determine whether the export key should proceed.
 *
 *
 *  Parameters:
 *               IN      pTmpUser     -  Pointer to the user list structure
 *               IN      dwKeySpec    -  Type of key to be exported
 *
 *  Returns:
 */
BOOL CryptConfirmExportKey(
                           IN PNTAGUserList pTmpUser,
                           IN DWORD dwKeySpec
                           )
{
    DWORD   dwResult = TRUE;

#ifdef _USE_UI
    DIALOG_INFO Info;

    if (!GetDialogInfo(pTmpUser, EXPORT_PRIV_TXT, dwKeySpec, &Info))
        dwResult = FALSE;
    else
    {
        if (-1 == (dwResult = DialogBoxParam(hInstance,
                                             MAKEINTRESOURCE(IDD_SOLICIT_PASSWORD),
                                             pTmpUser->hWnd,
                                             (DLGPROC)DialogSolicitPassword,
                                             (long)&Info)))
            dwResult = FALSE;
    }
#endif // _USE_UI
#ifdef MESSAGEBOXES
    int     ret;

    if (pTmpUser->hUID !=  0xdeadbeef)
    {
	SetLastError(NTE_BAD_UID);
	return CPPAPI_FAILED;
    }

    if (hKey == 0)
    {
	SetLastError(NTE_BAD_KEY);
	return CPPAPI_FAILED;
    }

    ret = MessageBox(NULL, "Type password", "CryptConfirmExportKey", MB_OK);
#endif

    return dwResult;
}

/*
 -  CryptConfirmImportKey
 -
 *  Purpose:
 *                Determine whether the import key should proceed.
 *
 *
 *  Parameters:
 *               IN      pTmpUser     -  Pointer to the user list structure
 *               IN      pKey         -  Pointer to the key list structure
 *               IN      dwBlobType   -  Type of blob to be imported
 *               IN      dwKeySpec    -  Type of key to be imported
 *
 *  Returns:
 */
BOOL CryptConfirmImportKey(
                           IN PNTAGUserList pTmpUser,
                           IN DWORD dwBlobType,
                           IN DWORD dwKeySpec
                           )
{
    BOOL    fOverwrite = FALSE;
    DWORD   dwResult = TRUE;

#ifdef _USE_UI
    DIALOG_INFO Info;

    if (PRIVATEKEYBLOB == dwBlobType)
    {
        if (AT_SIGNATURE == dwKeySpec)
        {
            if (pTmpUser->SigPrivLen)
                fOverwrite = TRUE;
        }
        else
        {
            if (pTmpUser->ExchPrivLen)
                fOverwrite = TRUE;
        }

        if (fOverwrite)
        {
            if (!GetDialogInfo(pTmpUser, IMPORT_PRIV_OVER_TXT, dwKeySpec, &Info))
                dwResult = FALSE;
            else
            {
                if (-1 == (dwResult = DialogBoxParam(hInstance,
                                                     MAKEINTRESOURCE(IDD_OVERWRITE_PASSWORD),
                                                     pTmpUser->hWnd,
                                                     (DLGPROC)DialogOverwritePassword,
                                                     (long)&Info)))
                    dwResult = FALSE;
            }
        }
        else
        {
            if (!GetDialogInfo(pTmpUser, IMPORT_PRIV_NO_OVER_TXT, dwKeySpec, &Info))
                dwResult = FALSE;
            else
            {
                if (-1 == (dwResult = DialogBoxParam(hInstance,
                                                     MAKEINTRESOURCE(IDD_NEW_PASSWORD),
                                                     pTmpUser->hWnd,
                                                     (DLGPROC)DialogNewPassword,
                                                     (long)&Info)))
                    dwResult = FALSE;
            }
        }
    }
    else if (SIMPLEBLOB == dwBlobType)
    {
        if (!GetDialogInfo(pTmpUser, IMPORT_SIMPLE_TXT, dwKeySpec, &Info))
            dwResult = FALSE;
        else
        {
            if (-1 == (dwResult = DialogBoxParam(hInstance,
                                                 MAKEINTRESOURCE(IDD_SOLICIT_PASSWORD),
                                                 pTmpUser->hWnd,
                                                 (DLGPROC)DialogSolicitPassword,
                                                 (long)&Info)))
                dwResult = FALSE;
        }
    }

#endif // _USE_UI

    return dwResult;
}

/*
 -  CryptConfirmGenKey
 -
 *  Purpose:
 *                Determine whether the gen key should proceed.
 *
 *
 *  Parameters:
 *               IN      pTmpUser     -  Pointer to the user list structure
 *               IN      pKey         -  Pointer to the key list structure
 *               IN      dwKeySpec    -  Type of key to be imported
 *
 *  Returns:
 */
BOOL CryptConfirmGenKey(
                        IN PNTAGUserList pTmpUser,
                        IN DWORD dwKeySpec
                        )
{
    BOOL    fOverwrite = FALSE;
    DWORD   dwResult = TRUE;

#ifdef _USE_UI
    DIALOG_INFO Info;

    if (AT_SIGNATURE == dwKeySpec)
    {
        if (pTmpUser->SigPrivLen)
            fOverwrite = TRUE;
    }
    else
    {
        if (pTmpUser->ExchPrivLen)
            fOverwrite = TRUE;
    }

    if (fOverwrite)
    {
        if (!GetDialogInfo(pTmpUser, GENKEY_OVER_TXT, dwKeySpec, &Info))
            dwResult = FALSE;
        else
        {
            if (-1 == (dwResult = DialogBoxParam(hInstance,
                                                 MAKEINTRESOURCE(IDD_OVERWRITE_PASSWORD),
                                                 pTmpUser->hWnd,
                                                 (DLGPROC)DialogOverwritePassword,
                                                 (long)&Info)))
                dwResult = FALSE;
        }
    }
    else
    {
        if (!GetDialogInfo(pTmpUser, GENKEY_NO_OVER_TXT, dwKeySpec, &Info))
            dwResult = FALSE;
        else
        {
            if (-1 == (dwResult = DialogBoxParam(hInstance,
                                                 MAKEINTRESOURCE(IDD_NEW_PASSWORD),
                                                 pTmpUser->hWnd,
                                                 (DLGPROC)DialogNewPassword,
                                                 (long)&Info)))
                dwResult = FALSE;
        }
    }
#endif // _USE_UI

    return dwResult;
}

/*
 -  CryptConfirmChangePassword
 -
 *  Purpose:
 *                Determine whether the key password should be changed.
 *
 *
 *  Parameters:
 *               IN      pTmpUser     -  Pointer to the user list structure
 *               IN      dwKeySpec    -  Type of key changing the password for
 *
 *  Returns:
 */
BOOL CryptConfirmChangePassword(
                                IN PNTAGUserList pTmpUser,
                                IN DWORD dwKeySpec
                                )
{
    DWORD   dwResult = TRUE;

#ifdef _USE_UI
    DIALOG_INFO Info;

    if (!GetDialogInfo(pTmpUser, SETKEYPARAM_CHGPWD_TXT, dwKeySpec, &Info))
        dwResult = FALSE;
    else
    {
        if (-1 == (dwResult = DialogBoxParam(hInstance,
                                             MAKEINTRESOURCE(IDD_OVERWRITE_PASSWORD),
                                             pTmpUser->hWnd,
                                             (DLGPROC)DialogOverwritePassword,
                                             (long)&Info)))
            dwResult = FALSE;
    }
#endif // _USE_UI

    return dwResult;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -