use of com.google.crypto.tink.proto.AesEaxKey in project tink by google.
the class RegistryTest method testGetPrimitive_AesGcm_shouldWork.
@Test
public void testGetPrimitive_AesGcm_shouldWork() throws Exception {
KeyTemplate template = AeadKeyTemplates.AES128_EAX;
AesEaxKey aesEaxKey = (AesEaxKey) Registry.newKey(template);
KeyData aesEaxKeyData = Registry.newKeyData(template);
Aead aead = Registry.getPrimitive(aesEaxKeyData);
assertThat(aesEaxKey.getKeyValue().size()).isEqualTo(16);
assertThat(aesEaxKeyData.getTypeUrl()).isEqualTo(AeadConfig.AES_EAX_TYPE_URL);
// This might break when we add native implementations.
assertThat(aead.getClass()).isEqualTo(AesEaxJce.class);
}
use of com.google.crypto.tink.proto.AesEaxKey in project tink by google.
the class AesEaxKeyManagerTest method testNewKeyMultipleTimes.
@Test
public void testNewKeyMultipleTimes() throws Exception {
AesEaxKeyFormat eaxKeyFormat = AesEaxKeyFormat.newBuilder().setParams(AesEaxParams.newBuilder().setIvSize(16).build()).setKeySize(16).build();
ByteString serialized = ByteString.copyFrom(eaxKeyFormat.toByteArray());
KeyTemplate keyTemplate = KeyTemplate.newBuilder().setTypeUrl(AesEaxKeyManager.TYPE_URL).setValue(serialized).build();
AesEaxKeyManager keyManager = new AesEaxKeyManager();
Set<String> keys = new TreeSet<String>();
// Calls newKey multiple times and make sure that they generate different keys.
int numTests = 27;
for (int i = 0; i < numTests / 3; i++) {
AesEaxKey key = (AesEaxKey) keyManager.newKey(eaxKeyFormat);
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
key = (AesEaxKey) keyManager.newKey(serialized);
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
KeyData keyData = keyManager.newKeyData(keyTemplate.getValue());
key = AesEaxKey.parseFrom(keyData.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
assertEquals(16, key.getKeyValue().toByteArray().length);
}
assertEquals(numTests, keys.size());
}
use of com.google.crypto.tink.proto.AesEaxKey in project tink by google.
the class AesEaxKeyManager method getPrimitive.
/**
* @param key {@code AesEaxKey} proto
*/
@Override
public Aead getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof AesEaxKey)) {
throw new GeneralSecurityException("expected AesEaxKey proto");
}
AesEaxKey keyProto = (AesEaxKey) key;
validate(keyProto);
return new AesEaxJce(keyProto.getKeyValue().toByteArray(), keyProto.getParams().getIvSize());
}
Aggregations