#hybrid #tink #public-key

tin-kai-hu-yun

为 Google 的 Tink 密码库 Rust 端提供的混合加密功能

3 个版本

0.2.5 2023 年 3 月 14 日
0.2.4 2022 年 3 月 25 日
0.2.3 2022 年 1 月 3 日

#11#tink

Download history 31/week @ 2024-04-20 28/week @ 2024-04-27 45/week @ 2024-05-04 104/week @ 2024-05-11 60/week @ 2024-05-18 47/week @ 2024-05-25 25/week @ 2024-06-01 63/week @ 2024-06-08 63/week @ 2024-06-15 48/week @ 2024-06-22 94/week @ 2024-06-29 36/week @ 2024-07-06 24/week @ 2024-07-13 44/week @ 2024-07-20 25/week @ 2024-07-27 19/week @ 2024-08-03

119 每月下载量
用于 rinkey

Apache-2.0

310KB
5K SLoC

Tink-Rust:混合加密

Docs MSRV

本包提供了混合加密功能,详细说明见上游 Tink 文档

使用方法

fn main() -> Result<(), Box<dyn Error>> {
    tink_hybrid::init();
    let kh_priv = tink_core::keyset::Handle::new(
        &tink_hybrid::ecies_hkdf_aes128_ctr_hmac_sha256_key_template(),
    )?;

    // NOTE: save the private keyset to a safe location. DO NOT hardcode it in source code.
    // Consider encrypting it with a remote key in Cloud KMS, AWS KMS or HashiCorp Vault.  See
    // https://github.com/google/tink/blob/master/docs/GOLANG-HOWTO.md#storing-and-loading-existing-keysets.

    let kh_pub = kh_priv.public()?;

    // NOTE: share the public keyset with the sender.

    let enc = tink_hybrid::new_encrypt(&kh_pub)?;

    let msg = b"this data needs to be encrypted";
    let encryption_context = b"encryption context";
    let ct = enc.encrypt(msg, encryption_context)?;

    let dec = tink_hybrid::new_decrypt(&kh_priv)?;

    let pt = dec.decrypt(&ct, encryption_context)?;
    assert_eq!(msg[..], pt);

    println!("Ciphertext: {}\n", hex::encode(&ct));
    println!("Original  plaintext: {}\n", String::from_utf8_lossy(msg));
    println!("Decrypted plaintext: {}\n", String::from_utf8_lossy(&pt));
    Ok(())
}

许可证

Apache 许可证,版本 2.0

免责声明

这不是 Google 的官方支持产品。

依赖项

~4.5–7MB
~128K SLoC