use of com.google.crypto.tink.proto.AesSivKey in project tink by google.
the class AesSivKeyManagerTest method testNewKeyMultipleTimes.
@Test
public void testNewKeyMultipleTimes() throws Exception {
for (KeyTemplate keyTemplate : keyTemplates) {
AesSivKeyManager keyManager = new AesSivKeyManager();
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++) {
AesSivKey key = (AesSivKey) keyManager.newKey(keyTemplate.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
KeyData keyData = keyManager.newKeyData(keyTemplate.getValue());
key = AesSivKey.parseFrom(keyData.getValue());
keys.add(TestUtil.hexEncode(key.getKeyValue().toByteArray()));
}
assertEquals(numTests * 2, keys.size());
}
}
use of com.google.crypto.tink.proto.AesSivKey in project tink by google.
the class AesSivKeyManager method getPrimitive.
/**
* @param key {@code AesSivKey} proto
*/
@Override
public DeterministicAead getPrimitive(MessageLite key) throws GeneralSecurityException {
if (!(key instanceof AesSivKey)) {
throw new GeneralSecurityException("expected AesSivKey proto");
}
AesSivKey keyProto = (AesSivKey) key;
validate(keyProto);
return new AesSiv(keyProto.getKeyValue().toByteArray());
}
Aggregations