如何禁用由Wincrypt API完成的加密
问题描述:
我想禁用在Wincrypt API中加密的加密。
请给我点建议,如何做到这一点,一般sugestions也欢迎
下面是从EncryptedMessage.cpp代码示例:如何禁用由Wincrypt API完成的加密
CCryptoEngine::CryptProvider CCryptoEngine::
GetCryptoProvider()
throw(CCryptoEngine::Exception)
{
if(! CryptProviderAllocator::IsAllocated(m_RSACryptProvider))
{
if(! CryptAcquireContext(&m_RSACryptProvider, _T("CollabWorx SIM Client"),
MS_ENHANCED_PROV, PROV_RSA_FULL, 0))
if(! CryptAcquireContext(&m_RSACryptProvider, _T("CollabWorx SIM Client"),
MS_ENHANCED_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET))
if(! CryptAcquireContext(&m_RSACryptProvider, NULL, MS_ENHANCED_PROV,
PROV_RSA_FULL, CRYPT_NEWKEYSET | CRYPT_VERIFYCONTEXT))
throw CCryptoEngine::Exception(
"Your system may lack the required security capabilities.\n"
"Please make sure that Microsoft High Encryption Pack (128-bit strength) "
"is installed in your system.\n\nInformation for the support:\n"
+ GetErrorMessageFromCode(GetLastError()));
g_RSACryptProvider = m_RSACryptProvider;
}
return m_RSACryptProvider;
}
答
:
EncryptedMessage Encrypt(TextMessage& Msg, const KeyBlob& RecipientExchangeKeyBlob)
throw(CCryptoEngine::Exception)
{
CryptProvider CryptProvider = GetCryptoProvider();
CryptKey SessionKey = CreateSessionKey(CryptProvider);
CryptKey RecipientExchangeKey = ImportExchangeKey(CryptProvider,
RecipientExchangeKeyBlob);
KeyBlob SessionKeyBlob = CreateSessionKeyBlob(SessionKey, RecipientExchangeKey);
if(! CryptEncrypt(SessionKey, 0, TRUE, 0,
Msg.Text(), &Msg.Size(), Msg.Capacity()))
throw CCryptoEngine::Exception(ResourceString(IDS_CREN_MSG_ENC_FAILED) +
GetErrorMessageFromCode(GetLastError()));
KeyBlob SignatureBlob; //Empty signature
return EncryptedMessage(SessionKeyBlob, Msg, SignatureBlob);
}
从另一个类下面剪断有用的代码
如果你想解密加密的信息,你应该使用CryptDecrypt
函数。
,你应该使用相同的SessionKey
作为加密方法用于解密加密消息的人。
“...禁用在Wincrypt API中加密的加密。” - 你是否说要解密*使用Wincrypt API加密的内容?你的措辞并没有帮助你的问题的清晰。 – WhozCraig
已标记:不明 –
@WhoizCraig:是多数民众赞成在什么我想说 – ojas