Share via

Need some HELP with a function return

TIM 61 Reputation points
2022-03-03T17:56:03.26+00:00

Please do not judge; I am out of my element in C++., but trying to learn. Again, please do not judge - I am trying to use a function that decrypts an AES 256 bit message with CAPICOM. When I run my program in the VC++ (VS 2008) debugger, I can clearly see the decrypted string in _bstr_t variable:( plainText). When the value is passed back to the calling program, the content is missing. Here is the function call in my program, and the entire CAPICOM Decrypt function. I have a C background, and proficient in VB. Trying to wrap my addled brain around the necessary * chars below satisfied the compiler. ANY and ALL assistance will be so very appreciated - I've hit the wall.

Tim

*sDataCID = *Decrypt(sDataCID, sKey);

char *Decrypt(char *pszStr, char *pszKey)
{
int size;
char *buf;
//char plainText;
_bstr_t plainText;

IEncryptedDataPtr encryptor;

size = strlen(pszStr);

buf = new char[size + 1];
buf[size] = 0;

encryptor.CreateInstance("CAPICOM.EncryptedData");

encryptor->SetSecret(_bstr_t(pszKey), CAPICOM_SECRET_PASSWORD);

encryptor->Decrypt(_bstr_t(pszStr));
plainText = encryptor->GetContent();


return plainText;

}

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


Answer accepted by question author

Castorix31 91,876 Reputation points
2022-03-03T18:24:27.767+00:00

You can see Example: Convert from _bstr_t

or you can declare :

LPWSTR Decrypt(char* pszStr, char* pszKey)  

then

  LPWSTR pString = Decrypt(sDataCID, sKey);  

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.