我剛剛包裝了一個頭文件(.h)並創建了.so文件,將它用作python中的模塊。函數Encrypt使用char * bb,然後使用memcpy()填充它。如果我想從c代碼中調用這個函數(char * bb =(char *)new char [200]; Encrypt(...,...,...,bb);)。如何從python調用它? Python中的(char * bb =(char *)new char [200];)如何相等?python中的char *問題
int Encrypt (string key, string iv, string plaintext, char* bb)
{
std::string ciphertext;
CryptoPP::AES::Encryption aesEncryption((byte *)key.c_str(), CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, (byte *)iv.c_str());
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink(ciphertext));
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(plaintext.c_str()), plaintext.length());
stfEncryptor.MessageEnd();
memcpy(bb,ciphertext.c_str(), ciphertext.size());
return ciphertext.size();
};
從C調用加密():
char* bbb = (char*) new char [400];
int sizec = Encrypt(key, iv, plaintext, bbb);
我用create_string_buffer( 「」,400)在python,但它不工作。
「如果我想從ac代碼中調用這個函數,我必須做`char * bb =(char *)new char [200];`...」你的意思是C++,而不是C。不必要。 – 2011-01-13 09:16:02
這是什麼`char * bbb =(char *)new char [400];`?你不需要投。只需`char * bbb = new char [400];`就夠了! – Nawaz 2011-01-13 09:17:49