Search in sources :

Example 1 with AesSivKey

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());
    }
}
Also used : TreeSet(java.util.TreeSet) AesSivKey(com.google.crypto.tink.proto.AesSivKey) ByteString(com.google.protobuf.ByteString) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) KeyData(com.google.crypto.tink.proto.KeyData) Test(org.junit.Test)

Example 2 with AesSivKey

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());
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) AesSivKey(com.google.crypto.tink.proto.AesSivKey) AesSiv(com.google.crypto.tink.subtle.AesSiv)

Aggregations

AesSivKey (com.google.crypto.tink.proto.AesSivKey)2 KeyData (com.google.crypto.tink.proto.KeyData)1 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)1 AesSiv (com.google.crypto.tink.subtle.AesSiv)1 ByteString (com.google.protobuf.ByteString)1 GeneralSecurityException (java.security.GeneralSecurityException)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1