本文介绍了如何使用Google Tink创建对称加密密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个密钥(例如) thisist0psecret,我想用作的对称加密/解密密钥。我为自己做不到这一简单的事情而感到困惑。我可以生成新密钥(使用各种模板AES128_GCM等),对其进行序列化,然后使用KeysetReader将其读回。但是,对于我一生来说,我无法弄清楚如何使用我指定的特定密钥字节创建一个对称密钥。

I have a key (say) "thisist0psecret" that I want to use as a symmetric encryption/decryption key with the Google Tink library. I am baffled that I am unable to do this simple thing. I can generate new keys (using various templates AES128_GCM, etc.), serialize them and then read them back with KeysetReader. But, for the life of me, I cannot figure out how to create a symmetric key with the specific key bytes that I specify.

我能够做到以下示例,例如,使用Tink:

I am able to do the following, for example, with Tink:

KeysetHandle ksh = KeysetHandle.generateNew(AeadKeyTemplates.AES128_GCM);
Aead aead = AeadFactory.getPrimitive(ksh);
String pt = "hello, world!";
byte[] encbytes = aead.encrypt(pt.getBytes(), null);
byte[] decbytes = aead.decrypt(encbytes, null);
String orig = new String(decbytes);
assert(pt.equals(orig));

但是我想将对称密钥字符串设置为我指定的一组字节,例如 thisist0psecret。然后使用将进行解密的用户的公钥对该密钥进行加密。

But I want to set the symmetric key string to be a set of bytes that I specify such as "thisist0psecret" and then encrypt this key with the public key of the user who will do the decryption.

这里有任何Google Tink专家可以透露一些信息吗?

Any Google Tink experts here that can shed some light?

推荐答案

我是Tink的首席开发人员。

I'm the lead developer for Tink.

如果密钥是随机生成的,则可以直接使用微妙的API,参见:。

If your key is randomly generated, you can use the subtle API directly, see: https://github.com/google/tink/blob/master/java_src/src/main/java/com/google/crypto/tink/subtle/AesGcmJce.java.

不建议这样做,因为微妙的层可能会更改,而不会发出通知(在Tink的历史中,它一直相对稳定)。

This is not recommended because the subtle layer might change without notice (thought it's been relatively stable in the history of Tink).

如果您的密钥是密码,则要使用Scrypt或PBKDF2之类的方法从中派生密钥。 Tink尚不支持基于密码的本地加密,请提出功能请求,我们将为您提供帮助。

If your key is a password you want to derive a key from it using something like Scrypt or PBKDF2. We haven't yet support native password-based encryption in Tink, please file a feature request and we'll see how we can help.

这篇关于如何使用Google Tink创建对称加密密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 20:31