use of com.google.crypto.tink.proto.ChaCha20Poly1305Key in project tink by google.
the class ChaCha20Poly1305KeyManagerTest method testNewKeyMultipleTimes.
@Test
public void testNewKeyMultipleTimes() throws Exception {
KeyTemplate keyTemplate = AeadKeyTemplates.CHACHA20_POLY1305;
ChaCha20Poly1305KeyManager keyManager = new ChaCha20Poly1305KeyManager();
Set<String> keys = new TreeSet<String>();
// Calls newKey multiple times and make sure that they generate different keys.
int numTests = 10;
for (int i = 0; i < numTests; i++) {
ChaCha20Poly1305Key key = (ChaCha20Poly1305Key) keyManager.newKey(keyTemplate.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(32, key.getKeyValue().toByteArray().length);
KeyData keyData = keyManager.newKeyData(keyTemplate.getValue());
key = ChaCha20Poly1305Key.parseFrom(keyData.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(32, key.getKeyValue().toByteArray().length);
}
assertEquals(numTests * 2, keys.size());
}
use of com.google.crypto.tink.proto.ChaCha20Poly1305Key in project tink by google.
the class ChaCha20Poly1305KeyManager method getPrimitive.
@Override
public Aead getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof ChaCha20Poly1305Key)) {
throw new GeneralSecurityException("expected ChaCha20Poly1305Key proto");
}
ChaCha20Poly1305Key keyProto = (ChaCha20Poly1305Key) key;
validate(keyProto);
return new ChaCha20Poly1305(keyProto.getKeyValue().toByteArray());
}
use of com.google.crypto.tink.proto.ChaCha20Poly1305Key in project tink by google.
the class ChaCha20Poly1305KeyManagerTest method createKey_values.
@Test
public void createKey_values() throws Exception {
ChaCha20Poly1305Key key = manager.keyFactory().createKey(ChaCha20Poly1305KeyFormat.getDefaultInstance());
assertThat(key.getVersion()).isEqualTo(0);
assertThat(key.getKeyValue()).hasSize(32);
}
Aggregations