Search in sources :

Example 81 with KeyTemplate

use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.

the class HmacKeyManagerTest method testNewKeyCorruptedFormat.

@Test
public void testNewKeyCorruptedFormat() throws Exception {
    HmacKeyManager keyManager = new HmacKeyManager();
    ByteString serialized = ByteString.copyFrom(new byte[128]);
    KeyTemplate keyTemplate = KeyTemplate.newBuilder().setTypeUrl(HmacKeyManager.TYPE_URL).setValue(serialized).build();
    try {
        keyManager.newKey(serialized);
        fail("Corrupted format, should have thrown exception");
    } catch (GeneralSecurityException expected) {
    // Expected
    }
    try {
        keyManager.newKeyData(keyTemplate.getValue());
        fail("Corrupted format, should have thrown exception");
    } catch (GeneralSecurityException expected) {
    // Expected
    }
}
Also used : ByteString(com.google.protobuf.ByteString) GeneralSecurityException(java.security.GeneralSecurityException) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 82 with KeyTemplate

use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.

the class DeterministicAeadKeyTemplatesTest method testAES256_SIV.

@Test
public void testAES256_SIV() throws Exception {
    KeyTemplate template = DeterministicAeadKeyTemplates.AES256_SIV;
    assertEquals(AesSivKeyManager.TYPE_URL, template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    AesSivKeyFormat format = AesSivKeyFormat.parseFrom(template.getValue());
    assertEquals(64, format.getKeySize());
}
Also used : AesSivKeyFormat(com.google.crypto.tink.proto.AesSivKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 83 with KeyTemplate

use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.

the class JsonKeysetReaderTest method testReadEncrypted_JsonKeysetWriter_shouldWork.

@Test
public void testReadEncrypted_JsonKeysetWriter_shouldWork() throws Exception {
    KeyTemplate masterKeyTemplate = AeadKeyTemplates.AES128_EAX;
    Aead masterKey = Registry.getPrimitive(Registry.newKeyData(masterKeyTemplate));
    KeysetHandle handle1 = KeysetHandle.generateNew(MacKeyTemplates.HMAC_SHA256_128BITTAG);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    handle1.write(JsonKeysetWriter.withOutputStream(outputStream), masterKey);
    KeysetHandle handle2 = KeysetHandle.read(JsonKeysetReader.withBytes(outputStream.toByteArray()), masterKey);
    assertKeysetHandle(handle1, handle2);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 84 with KeyTemplate

use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.

the class KeysetManagerTest method manipulateKeyset.

private void manipulateKeyset(KeysetManager manager) {
    try {
        KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
        manager.rotate(template).add(template).rotate(template).add(template);
    } catch (GeneralSecurityException e) {
        fail("should not throw exception: " + e);
    }
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate)

Example 85 with KeyTemplate

use of com.google.crypto.tink.proto.KeyTemplate in project tink by google.

the class JsonKeysetReaderTest method testRead_JsonKeysetWriter_shouldWork.

@Test
public void testRead_JsonKeysetWriter_shouldWork() throws Exception {
    KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
    KeysetHandle handle1 = KeysetHandle.generateNew(template);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    CleartextKeysetHandle.write(handle1, JsonKeysetWriter.withOutputStream(outputStream));
    KeysetHandle handle2 = CleartextKeysetHandle.read(JsonKeysetReader.withBytes(outputStream.toByteArray()));
    assertKeysetHandle(handle1, handle2);
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Aggregations

KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)119 Test (org.junit.Test)116 GeneralSecurityException (java.security.GeneralSecurityException)14 ByteString (com.google.protobuf.ByteString)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 EcdsaKeyFormat (com.google.crypto.tink.proto.EcdsaKeyFormat)11 HashType (com.google.crypto.tink.proto.HashType)11 KeyData (com.google.crypto.tink.proto.KeyData)11 HmacKeyFormat (com.google.crypto.tink.proto.HmacKeyFormat)8 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)7 AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)7 EllipticCurveType (com.google.crypto.tink.proto.EllipticCurveType)7 ByteArrayInputStream (java.io.ByteArrayInputStream)7 TreeSet (java.util.TreeSet)7 KeysetHandle (com.google.crypto.tink.KeysetHandle)6 AesCtrHmacAeadKeyFormat (com.google.crypto.tink.proto.AesCtrHmacAeadKeyFormat)6 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)6 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)6 EciesAeadHkdfKeyFormat (com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat)6 EciesHkdfKemParams (com.google.crypto.tink.proto.EciesHkdfKemParams)6