CryptEncrypt为不同的语言提供不同的结果
CryptEncrypt gives different results for different languages
当我在C++(如图所示)、C#或VB6中运行此代码时,我在CryptEncrypt中得到了不同的pbBuffer结果!我唯一能想到的是CryptEncrypt是基于语言的,或者其他函数的参数是错误的。发生这种情况的其他原因是什么?我是否向CryptDeriveKey传递了错误的参数?
if (CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0))
{
if (CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash))
{
if (CryptHashData(hHash, (BYTE *)szLocalPassword, _tcslen(szLocalPassword), 0))
{
if (CryptDeriveKey(hProv, CALG_RC4, hHash, CRYPT_EXPORTABLE, &hKey))
{
dwLength = sizeof(TCHAR)*_tcslen(sUnencryptedString);
BYTE *pbBuffer = (BYTE *)malloc(dwLength);
if (pbBuffer != NULL)
{
// Convert TCHAR to BYTE
char c_szText[128] = {0}; // Any char
SIZE_T so = wcslen(sUnencryptedString) + 1;
wcstombs(c_szText, sUnencryptedString, so);
memcpy(pbBuffer, c_szText, dwLength);
if (CryptEncrypt(hKey, 0, TRUE, 0, pbBuffer, &dwLength, dwLength))
这是VB代码,展示了如何将正确的信息传递给Crypto API,以在VB6中加密字符串。希望有人能在搜索时使用这些信息!
...
Dim bKeyRoot() As Byte
bKeyRoot = StrConv(sKeyRoot, vbFromUnicode)
lResult = CryptHashData(hHash, bKeyRoot(0), Len(sKeyRoot), 0)
...
Dim bText() As Byte
bText = StrConv(sText, vbFromUnicode)
lResult = CryptEncrypt(lKey, 0, 1, 0, bText(0), lClear, lData)
sText = StrConv(bText, vbUnicode)
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- valgrind-hellgrind与泄漏检查的结果不同
- 用C++20 fmt限制结果的总大小
- 如何返回一个类的两个对象相加的结果
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如果我std::dynamic_pointer_cast并且底层dynamic_cast的结果为null,那么返回的sh
- 在没有定义返回类型的函数中返回布尔值,并将结果保存在无错误的char编译中-为什么
- 序列化,没有库的整数,得到奇怪的结果
- 使用取消引用的指针的多态性会产生意外的结果.为什么?
- 不同语言中相同代码的不同行为
- 在更改for循环的第三部分后,未使用for循环结果
- 使用++运算符会导致意外的结果
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- C++Brute Force攻击函数不会返回结果
- 你好。。。id_public变量不应该给出结果为 81 和 86 吗?为什么它为两个派生类占用不同的内存位置?
- 算术运算的结果类似于:C浮点变量中的1/3
- ";结果类型必须是可从输入范围的值类型""构造的;创建std::vector时
- 密码登录程序将永远循环并显示不正确的结果
- 在这种情况下,GCC 和 clang 是否显示与 Visual Studio 相同的结果,关于语言链接?
- CryptEncrypt为不同的语言提供不同的结果