void Encrypt (char *pszFile, char *pszSecret) { int size; char *buf; _bstr_t cipherText; string name; ifstream in (pszFile, ios::in | ios::binary | ios::ate); ofstream out; IAlgorithmPtr algo; IEncryptedDataPtr encryptor; if ( !in.is_open() ) cout << szErrNoFile << std::endl; else { size = in.tellg(); buf = new char[size + 1]; buf[size] = 0; in.seekg(0, ios::beg); in.read(buf, size); in.close(); encryptor.CreateInstance("CAPICOM.EncryptedData"); encryptor->PutContent(_bstr_t (buf)); //I THINK ERROR IS HERE algo = encryptor->GetAlgorithm(); algo->PutName(CAPICOM_ENCRYPTION_ALGORITHM_AES); algo->PutKeyLength(CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM); encryptor->SetSecret(_bstr_t (pszSecret), CAPICOM_SECRET_PASSWORD); cipherText = encryptor->Encrypt(CAPICOM_ENCODE_BASE64); name = pszFile; name.append(".encrypted"); out.open(name.c_str(), ios::out | ios::binary); if ( !out.is_open() ) cout << szErrWrite << endl; else { out << cipherText; out.close(); } } }
encryptor
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)