将 Microsoft CryptoAPI 移植到 Mac 操作系统
我有一个 Windows 应用程序(使用 Visual Studio),它使用 微软加密API。现在需要开发Mac OS X 应用程序,能够读取由 WinApp 加密的数据, 并在 Mac OS X 上加密数据,该数据将由 WinApp 解密。 以这种方式初始化的 WinApp 中的加密/解密:
::CryptAcquireContext(&m_hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
::CryptCreateHash(m_hCryptProv, CALG_MD5, 0, 0, &m_hCryptHash);
::CryptHashData(m_hCryptHash, pbtPSW, dwPSWLen, 0);
::CryptDeriveKey(m_hCryptProv, CALG_RC4, m_hCryptHash, 0, &m_hCryptKey);
对于加密/解密,使用以下内容:
::CryptEncrypt(m_hCryptKey, 0, TRUE, 0, pBuf, &dwCnt, dwLen);
::CryptDecrypt(m_hCryptKey, 0, TRUE, 0, pBuf, &dwCnt);
据我了解,我需要找到一个实现 MD5 的库 哈希加上 RC4 编码/解码。似乎有一个 此类库的数量。例如:matrixSSL、OpenSSL。但 对我的 puroses 的库的使用并不明显(尤其是 考虑到我对 Sequurity/Crypting 不熟悉 蜜蜂)。有人可以推荐一个特定的加密库吗?可能 我的任务有代码示例吗?
添加:
看来主要问题是我需要 ::CryptDeriveKey 的便携式模拟,它与 Microsoft 版本兼容(即生成相同的密钥)。有人知道这样的吗?或者通过 ::CryptDeriveKey 创建密钥的算法?
I have a windows application (Visual Studio is used) that uses
Microsoft CryptoAPI. Now it is required to develop a Mac OS X
application, that is capable to read data, encrypted by the WinApp,
and encrypt data on Mac OS X, that will be decrypted by the WinApp.
Encryption/decription in the WinApp initialized in the such way:
::CryptAcquireContext(&m_hCryptProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
::CryptCreateHash(m_hCryptProv, CALG_MD5, 0, 0, &m_hCryptHash);
::CryptHashData(m_hCryptHash, pbtPSW, dwPSWLen, 0);
::CryptDeriveKey(m_hCryptProv, CALG_RC4, m_hCryptHash, 0, &m_hCryptKey);
And for encryption/decription the following is used:
::CryptEncrypt(m_hCryptKey, 0, TRUE, 0, pBuf, &dwCnt, dwLen);
::CryptDecrypt(m_hCryptKey, 0, TRUE, 0, pBuf, &dwCnt);
As I understand, I need to find a library that implements MD5
hashing plus RC4 encoding/decoding. It seems that there are a
number of such libraries. For example: matrixSSL, OpenSSL. But
using of the libraries for my puproses is not obvious (especially
taking into account, that I am not familiar with Sequrity/Crypting
APIs). Could somebody recommend a particular ciphering library? May
be there are code examples for my task?
ADDITION:
It seems the main problem is that I need a portable analog of the ::CryptDeriveKey, that is compatible with Microsoft version (i.e. generates the same key). Does anybody know a such one? Or an algorithm of creating a key by the ::CryptDeriveKey?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您查看 CyaSSL 嵌入式 SSL 库。它支持高达 TLS 1.2 的当前标准,并且跨操作系统非常便携。特别是,CyaSSL 包含 CTaoCrypt 加密库,它可以让您执行您正在寻找的加密操作。
CyaSSL 的一些有用文档链接:
CTaoCrypt 使用参考:http://yassl.com/yaSSL/Docs_CTaoCrypt_Usage_Reference .html
CyaSSL 文档页面:http://yassl.com/yaSSL/Docs.html
如果当您下载 CyaSSL 时,您还会发现一个 Visual Studio 项目文件可供查看。
问候,
克里斯
I would recommend taking a look at the CyaSSL embedded SSL library. It supports the current standards up to TLS 1.2 and is very portable across operating systems. In particular, CyaSSL includes the CTaoCrypt cryptographic library which should let you perform the crypto operations you're looking for.
Some helpful documentation links for CyaSSL:
CTaoCrypt Usage Reference: http://yassl.com/yaSSL/Docs_CTaoCrypt_Usage_Reference.html
CyaSSL Docs Page: http://yassl.com/yaSSL/Docs.html
If you download CyaSSL, you'll find a Visual Studio project file to take a look at as well.
Regards,
Chris