如何禁用 Wincrypt API 完成的加密

How to disable encryption done by Wincrypt API

我想禁用在 Wincrypt API 中加密的加密。
请给我建议,如何做,也欢迎一般性建议
以下是来自 EncryptedMessage.cpp 的代码示例:

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 );
  }

从另一个 class 下面截取的有用代码:

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;
}

如果你想解密加密的消息,你应该使用CryptDecrypt函数。

参见 MSDN 文档: https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=EN-US&k=k(Wincrypt%2FCryptDecrypt);k(CryptDecrypt);k(DevLang-C%2B%2B);k(TargetOS-Windows)&rd=true

根据您的代码,您应该使用与 Encrypt 方法中使用的代码相同的 SessionKey 来解密加密的消息。