首先环境需要安装VCPKG, https://github.com/microsoft/vcpkg
vcpkg install cryptopp ( x86 版本 vcpkg install cryptopp:x86-windows)
cmake_minimum_required(VERSION 3.29)
project(md5test)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
# 导入vcpkg
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/vcpkg/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "Vcpkg toolchain file")
# 设置目标ARCH x64-windows
set(VCPKG_TARGET_TRIPLET x86-windows)
find_package(cryptopp CONFIG REQUIRED)
add_executable(md5test main.cpp)
target_compile_options(${PROJECT_NAME} PRIVATE "/utf-8")
target_link_libraries(${PROJECT_NAME} PRIVATE cryptopp::cryptopp)
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <iomanip>
#include <iostream>
#include <cryptopp/md5.h>
int main() {
CryptoPP::Weak::MD5 md5;
std::string input = "hello world";
CryptoPP::byte digest[CryptoPP::Weak::MD5::DIGESTSIZE];
md5.CalculateDigest(digest, (const CryptoPP::byte*)input.data(), input.size());
std::cout << "MD5 digest: " << std::hex << std::setfill('0');
for (int i = 0; i < CryptoPP::Weak::MD5::DIGESTSIZE; i++) {
std::cout << std::setw(2) << (int)digest[i];
}
std::cout << std::endl;
return 0;
}
版权声明:本文为NII.CN的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://nii.cn/4285.html 发布者:nii