-3

I want to disable the encryption which is encrypted in Wincrypt API.
Please give me suggestions, how to do that, general sugestions are also welcomed
Below is the Code Samples from 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 );
  }

Useful Code Snipped from another class Below:

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;
}
Nikaido
  • 4,443
  • 5
  • 30
  • 47
ojas
  • 247
  • 1
  • 4
  • 17
  • 1
    "...disable the encryption which is encrypted in Wincrypt API." - are you saying you want to *decrypt* content encrypted with the Wincrypt API? Your phrasing is not helping the clarity of your question. – WhozCraig Mar 02 '16 at 18:10
  • @WhoizCraig: yes thats what i want to say – ojas Mar 02 '16 at 18:35
  • 1
    So are you saying you want to have a function that takes a `EncryptedMessage` and `KeyBlob` and returns a `TextMessage`? The question is very unclear. We don't have access to your classes as well, it seems. Please provide a [MCVE](/help/mcve). – Alyssa Haroldsen Mar 07 '16 at 18:59
  • oki sure. give me some time.. i will edit my question. i am taking time to edit because there are some security features which i am reluctant to show – ojas Mar 07 '16 at 20:05
  • 1
    Start by changing the title. – Martin Bonner supports Monica Mar 07 '16 at 20:24

1 Answers1

0

If you want to decrypt the encrypted message, you should use the CryptDecrypt function.

See MSDN document: 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

Based on your code, you should use the same SessionKey as the one used in the Encrypt method to decrypt the encrypted message.

Garland
  • 911
  • 7
  • 22