Search in sources :

Example 66 with KeyTemplate

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

the class JsonKeysetReaderTest method testRead_singleKey_shouldWork.

@Test
public void testRead_singleKey_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.withInputStream(new ByteArrayInputStream(outputStream.toByteArray())));
    assertKeysetHandle(handle1, handle2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 67 with KeyTemplate

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

the class JsonKeysetReaderTest method testReadEncrypted_singleKey_shouldWork.

@Test
public void testReadEncrypted_singleKey_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.withInputStream(new ByteArrayInputStream(outputStream.toByteArray())), masterKey);
    assertKeysetHandle(handle1, handle2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 68 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)

Example 69 with KeyTemplate

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

the class MacKeyTemplatesTest method hmacSha256_128BitTag.

@Test
public void hmacSha256_128BitTag() throws Exception {
    KeyTemplate template = MacKeyTemplates.HMAC_SHA256_128BITTAG;
    assertEquals(new HmacKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(32, format.getKeySize());
    assertEquals(16, format.getParams().getTagSize());
    assertEquals(HashType.SHA256, format.getParams().getHash());
}
Also used : HmacKeyFormat(com.google.crypto.tink.proto.HmacKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 70 with KeyTemplate

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

the class MacKeyTemplatesTest method hmacSha256_256BitTag.

@Test
public void hmacSha256_256BitTag() throws Exception {
    KeyTemplate template = MacKeyTemplates.HMAC_SHA256_256BITTAG;
    assertEquals(new HmacKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    HmacKeyFormat format = HmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(32, format.getKeySize());
    assertEquals(32, format.getParams().getTagSize());
    assertEquals(HashType.SHA256, format.getParams().getHash());
}
Also used : HmacKeyFormat(com.google.crypto.tink.proto.HmacKeyFormat) 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