g++ -I../cryptopp/cryptopp/output/include -o test main.cpp ../cryptopp/cryptopp/output/lib/libcryptopp.a
string sPublicKey = "3059301306072A8648CE3D020106082A8648CE3D03010703420004BD8E4960D48F8D0AE1FEEFB69F4E3ED1BAC125F88968C25BCDB19CFEF1A4423EFECDCF348EE59C0EF2AF01DF994951C96A3FBDBF26EC58CC90B003AF7D1522E9";
string sPrivateKey = "3041020100301306072A8648CE3D020106082A8648CE3D030107042730250201010420C9F3A236525B737E0FA48C8375D6379FCF0A26D367EEC5DFBBF330ADE501D0F6";
std::string cipherText;
StringSource pubString(sPublicKey, true, new HexDecoder);
string msgToEncrypt = "tests";
ECIES<ECP>::Encryptor encryptor(pubString);
size_t uiCipherTextSize = encryptor.CiphertextLength(msgToEncrypt.size());
cipherText.resize(uiCipherTextSize);
RandomPool rnds;
encryptor.Encrypt(rnds, (byte*)msgToEncrypt.c_str(), msgToEncrypt.size(), (byte*)cipherText.data());
std::string decryptText;
StringSource priString(sPrivateKey, true, new HexDecoder);
ECIES<ECP>::Decryptor decryptor(priString);
struct timeval tpstart,tpend;
float timeuse = 0;
int count = 10000;
gettimeofday(&tpstart,NULL);
while(count--){
size_t uiDecryptTextSize = decryptor.MaxPlaintextLength(cipherText.size());
decryptText.resize(uiDecryptTextSize);
RandomPool rndss;
decryptor.Decrypt(rndss, (byte*)cipherText.c_str(), cipherText.size(), (byte*)decryptText.data());
}
gettimeofday(&tpend,NULL);
timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
printf("ecies used:%f ms\n", timeuse/1000);
在 2020年7月21日星期二 UTC+8上午1:00:36,Jeffrey Walton写道: