使用加密++; 我试图使用密码+ +,但我没有太多C++经验。我正在尝试从AES开始对加密和解密进行性能测试。我将安装作为源代码,我可以如下所示包含它,但是当我尝试使用Xcode编译和运行时,它会引发38个链接错误,从 CryptoPP::AlignedAllocate(unsigned long)", referenced from: CryptoPP::AllocatorWithCleanup<unsigned char, true>::allocate(unsigned long, void const*) in main.o` CryptoPP::AlignedAllocate(无符号长)”引用自: CryptoPP::AllocatorWithCleanup::allocate(无符号长, main.o中的void const*)`
这是我的密码:使用加密++; 我试图使用密码+ +,但我没有太多C++经验。我正在尝试从AES开始对加密和解密进行性能测试。我将安装作为源代码,我可以如下所示包含它,但是当我尝试使用Xcode编译和运行时,它会引发38个链接错误,从 CryptoPP::AlignedAllocate(unsigned long)", referenced from: CryptoPP::AllocatorWithCleanup<unsigned char, true>::allocate(unsigned long, void const*) in main.o` CryptoPP::AlignedAllocate(无符号长)”引用自: CryptoPP::AllocatorWithCleanup::allocate(无符号长, main.o中的void const*)`,c++,encryption,crypto++,C++,Encryption,Crypto++,这是我的密码: #include <iostream> #include <fstream> #include <sstream> #include <string> #include <string.h> #include <chrono> #include <unistd.h> #include </usr/include/cryptopp/aes.h> #include </usr/
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <string.h>
#include <chrono>
#include <unistd.h>
#include </usr/include/cryptopp/aes.h>
#include </usr/include/cryptopp/modes.h>
#include </usr/include/cryptopp/filters.h>
using namespace std;
const int stringlength = 1000;
char *stringdir = "/Users/Noah/Desktop/EncryptionTimer/EncryptionTimer/strings/";
char *read(const char *filepath)
{
FILE *file = fopen(filepath, "r");
fseek(file, 0, SEEK_END);
long int length = ftell(file);
char *buffer = (char*) malloc(sizeof(char) * length + 1);
rewind(file);
fread(buffer, 1, length, file);
fclose(file);
buffer[-1] = '\0';
return buffer;
}
int main(int argc, const char * argv[])
{
fstream fout("./output.txt");
for (int fileindex = 1; fileindex <= 1; fileindex++)
{
ostringstream convert;
convert << fileindex;
string name = convert.str() + ".txt";
char *filename = new char[name.size() + 1];
copy(name.begin(), name.end(), filename);
filename[-1] = '\0';
char *filepath = new char[sizeof(*stringdir) + sizeof(*filename)];
strncat(filepath, stringdir, strlen(stringdir));
strncat(filepath, filename, strlen(filename));
cout << filepath << "...";
fout << filepath << "...";
char *contents = read(filepath);
string plaintext = string(contents);
string ciphertext;
byte key[CryptoPP::AES::DEFAULT_KEYLENGTH], iv[CryptoPP::AES::BLOCKSIZE];
memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH);
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE);
cout << "ready" << "...";
fout << "ready" << "...";
// Encrypt
auto t_start1 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 1000; i++)
{
CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption(aesEncryption, iv);
CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink(ciphertext));
stfEncryptor.Put(reinterpret_cast<const unsigned char*>(plaintext.c_str()), plaintext.length() + 1);
stfEncryptor.MessageEnd();
}
auto t_end1 = std::chrono::high_resolution_clock::now();
fout << "\nElapsed encrypt time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(t_end1 - t_start1).count()
<< " microseconds\n" << endl;
cout << "finished..." << endl;
// Decrypt
auto t_start2 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < 1000; i++)
{
CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink(ciphertext));
stfDecryptor.Put(reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size());
stfDecryptor.MessageEnd();
}
auto t_end2 = std::chrono::high_resolution_clock::now();
fout << "\nElapsed decrypt time: "
<< std::chrono::duration_cast<std::chrono::microseconds>(t_end2 - t_start2).count()
<< " microseconds\n" << endl;
cout << "\nDecryption Finished" << endl;
}
fout.close();
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
常量int stringlength=1000;
char*stringdir=“/Users/Noah/Desktop/EncryptionTimer/EncryptionTimer/strings/”;
字符*读取(常量字符*文件路径)
{
FILE*FILE=fopen(文件路径,“r”);
fseek(文件,0,SEEK_END);
long int length=ftell(文件);
char*buffer=(char*)malloc(sizeof(char)*长度+1);
倒带(文件);
fread(缓冲区,1,长度,文件);
fclose(文件);
缓冲区[-1]='\0';
返回缓冲区;
}
int main(int argc,const char*argv[]
{
fstream fout(“./output.txt”);
对于(int fileindex=1;fileindex
当我尝试编译和运行(使用Xcode)时,它会引发38个链接错误
您需要将Crypto++标头和库添加到Xcode项目中。下面的图像取自,并假定Crypto++安装在/usr/local/cryptopp
中
在此处添加标题:
在此处添加库:
如果您是为iOS交叉编译(也是Mach-O),Crypto++wiki有几个关于这个主题的页面:
如果您想使用ARMv7、ARMv7s、ARM64和i386(模拟器)为iOS预先构建Crypto++,请参见此
在自己创建库之前,应该打开makefile(GNUmakefile
),并取消注释cxflags=-fPIC
<> P>也因为<代码> >包含< /C> >,您可能需要添加<代码> CXXFLAG++-STDC++11 。我不确定,因为我不记得尝试MIC C++ 03和C++ 11。
Crypto++5.6.2及更早版本在Intel平台上也需要-dcryptoppp\u DISABLE\u ASM
,因为Clang的集成汇编程序和Apple的底层链接器
Crypto++5.6.3及以上版本解决了大多数问题。无法有效解决的问题已将-DCRYPTOPP\u DISABLE\u ASM
应用于有问题的翻译单元,而不是整个库