使用CryptoAPI加解密的程序,在XP上运行良好,在2000上加密会错,都不知道什么原因?

hthbserver 2006-02-22 09:55:28
server端:
1 导出公私密码对的公钥
2 发送给client端

client端:
1 导入收到的公钥数据得到了正确的HCRYPTKEY句柄
2 加密自己的数据
b = CryptImportKey(hProv, k.pKey, k.len, 0, 0, &hPubKey);
char pass[1024];
memset(pripass,0,1024);
strcpy(pripass,"myprivatepassword");
strcpy(pass,"myprivatepassword");

DWORD dwCount = strlen(pass);
b = CryptEncrypt(hPubKey, 0, TRUE, 0, (BYTE*)pass, &dwCount, 1024);
在XP下返回b为1,说明加密正确,但在2000下返回了0,出错,错误提示为:不正确的项.

有高手知道这是怎么回事吗?
...全文
219 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hthbserver 2006-02-23
  • 打赏
  • 举报
回复
继续
rageliu 2006-02-22
  • 打赏
  • 举报
回复
刚看了下文档!支持2000的
Under some circumstances, Microsoft cryptographic service providers may not allow encryption when used in France, in which case this function fails with the error code NTE_PERM. This may occur on down-level platforms such as Windows 95, Windows 98, and Windows NT 4.0, depending on the system's configuration and the version of the CSPs. When executing on these platforms, an application should check for this condition and behave accordingly.
hthbserver 2006-02-22
  • 打赏
  • 举报
回复
肯定正确呀,程序完全相同,在XP下正确的参数,在2000下也正确呀.
rageliu 2006-02-22
  • 打赏
  • 举报
回复
CryptEncrypt()使用前判断参数是否正确
hthbserver 2006-02-22
  • 打赏
  • 举报
回复
看样子是我2000上的platforms SDK版本太低引起的,但是我的client端需要在更低的版本运行,那我该怎么办?

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧