VSCode 使用VCPKG CMAKE 调用Cryptopp库

首先环境需要安装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

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
nii的头像nii
上一篇 2024-04-05
下一篇 2024-04-23

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

邮件:83390286[AT]QQ.COM

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信