专栏名称: 聊聊架构
聊聊架构
目录
相关文章推荐
51好读  ›  专栏  ›  聊聊架构

谷歌正式开源其多语言跨平台加密库Tink

聊聊架构  · 公众号  · 架构  · 2018-09-05 09:17

正文

请到「今天看啥」查看全文


GitHub 地址:https://github.com/google/tink

Tink 致力于提供安全且易于使用的加密 API。Tink 建立在现有的库之上,如 BoringSSL 和 Java Cryptography Architecture,同时对这些库中存在的弱点进行了加固。

有了 Tink,很多常见的加密操作(如数据加密、数字签名等)只需几行代码即可完成。以下是使用 AEAD 接口加密和解密的示例(Java 版):

import com.google.crypto.tink.Aead;
import com.google.crypto.tink.KeysetHandle;
import com.google.crypto.tink.aead.AeadFactory;
import com.google.crypto.tink.aead.AeadKeyTemplates;
// 1. Generate the key material.
KeysetHandle keysetHandle = KeysetHandle.generateNew(AeadKeyTemplates.AES256_EAX);
// 2. Get the primitive.
Aead aead = AeadFactory.getPrimitive(keysetHandle);
// 3. Use the primitive.
byte[] plaintext = ...;
byte[] additionalData = ...;
byte[] ciphertext = aead.encrypt(plaintext, additionalData);

Tink 尽可能消除潜在的误用情况。例如,如果底层加密模式需要 nonce,而重用 nonce 会导致不安全,那么 Tink 就不允许用户传递 nonce。接口的安全保证必须由实现接口的每个基元来满足,这可能会排除掉某些加密模式。对于这些模式,不能将它们添加到现有接口中,因为这样会削弱接口的安全保证,而是添加新的接口,并适当地描述它们的安全保证。







请到「今天看啥」查看全文