设置 Tink C++

安装并设置 Tink 后,请继续执行后续步骤

兼容性

与所有库兼容 此外,还与 Tink C++ 兼容
语言 C++ >= 17
操作系统 UbuntuLTS >= 20.04 (x86_64)
macOS >= 12.5 Monterey (x86_64)
Windows Server >= 2019 (x86_64)
编译器 GCC >= 7.5.0
Apple Clang >= 14
MSVC >= 2019
构建系统 Bazel >= 7 LTS CMake >= 3.22

安装

Tink C++

核心 C++ 库为 tink-cc,最新版本为 2.4.0

Bazel

Bzlmod

将以下内容添加到 MODULE.bazel 文件中:

bazel_dep(name = "tink_cc", version = "2.4.0")

工作区

将以下内容添加到 WORKSPACE 文件中:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "tink_cc",
    urls = ["https://github.com/tink-crypto/tink-cc/archive/refs/tags/v2.4.0.zip"],
    strip_prefix = "tink-2.4.0",
    sha256 = "06c4d49b0b1357f0b8c3abc77a7d920130dc868e4597d432a9ce1cda4f65e382",
)

load("@tink_cc//:tink_cc_deps.bzl", "tink_cc_deps")

tink_cc_deps()

load("@tink_cc//:tink_cc_deps_init.bzl", "tink_cc_deps_init")

tink_cc_deps_init()

CMake

tink-cc 添加为树内依赖项。

cmake_minimum_required(VERSION 3.22)
project(YourProject CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 14)
include(FetchContent)

# Import Tink as an in-tree dependency.
FetchContent_Declare(
  tink
  URL       https://github.com/tink-crypto/tink-cc/archive/refs/tags/v2.4.0.zip
  URL_HASH  SHA256=06c4d49b0b1357f0b8c3abc77a7d920130dc868e4597d432a9ce1cda4f65e382
)
FetchContent_GetProperties(tink)
if(NOT googletest_POPULATED)
  FetchContent_Populate(tink)
    add_subdirectory(${tink_SOURCE_DIR} ${tink_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

add_executable(your_app your_app.cc)
target_link_libraries(your_app tink::static)

AWS KMS 扩展程序

Tink C++ AWS KMS 扩展程序是 tink-cc-awskms,最新版本为 2.0.1

Bazel

工作区

将以下内容添加到 WORKSPACE 文件中:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "tink_cc",
    urls = ["https://github.com/tink-crypto/tink-cc/archive/refs/tags/v2.4.0.zip"],
    strip_prefix = "tink-2.4.0",
    sha256 = "06c4d49b0b1357f0b8c3abc77a7d920130dc868e4597d432a9ce1cda4f65e382",
)

load("@tink_cc//:tink_cc_deps.bzl", "tink_cc_deps")

tink_cc_deps()

load("@tink_cc//:tink_cc_deps_init.bzl", "tink_cc_deps_init")

tink_cc_deps_init()

http_archive(
    name = "tink_cc_awskms",
    urls = ["https://github.com/tink-crypto/tink-cc-awskms/archive/refs/tags/v2.0.1.zip"],
    strip_prefix = "tink-cc-awskms-2.0.1",
    sha256 = "366319b269f62af120ee312ce4c99ce3738ceb23ce3f9491b4859432f8b991a4",
)

load("@tink_cc_awskms//:tink_cc_awskms_deps.bzl", "tink_cc_awskms_deps")

tink_cc_awskms_deps()

Google Cloud KMS 扩展服务

Tink C++ Google Cloud KMS 扩展程序为 tink-cc-gcpkms,最新版本为 2.4.0

Bazel

工作区

将以下内容添加到 WORKSPACE 文件中:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "tink_cc_gcpkms",
    urls = ["https://github.com/tink-crypto/tink-cc-gcpkms/releases/download/v2.4.0/tink-cc-gcpkms-2.4.0.zip"],
    strip_prefix = "tink-cc-gcpkms-2.4.0",
    sha256 = "b2c7803b03fcce2d52b15e97f871155d477ccf88b2146337d54202defd074418",
)

load("@tink_cc_gcpkms//:tink_cc_gcpkms_deps.bzl", "tink_cc_gcpkms_deps")

tink_cc_gcpkms_deps()

load("@tink_cc_gcpkms//:tink_cc_gcpkms_deps_init.bzl", "tink_cc_gcpkms_deps_init")

tink_cc_gcpkms_deps_init(register_go = True)

后续步骤

完成 Tink 设置后,请继续执行标准 Tink 使用步骤:

  • 选择一个基元 - 根据您的使用场景决定要使用哪个基元
  • 管理密钥 - 使用外部 KMS 保护密钥、生成密钥集和轮替密钥