Search in sources :

Example 11 with KeyTemplate

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

the class AesEaxKeyManagerTest method testAes256EaxTemplate.

@Test
public void testAes256EaxTemplate() throws Exception {
    KeyTemplate template = AesEaxKeyManager.aes256EaxTemplate();
    assertEquals(new AesEaxKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.TINK, template.getOutputPrefixType());
    AesEaxKeyFormat format = AesEaxKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(32, format.getKeySize());
    assertTrue(format.hasParams());
    assertEquals(16, format.getParams().getIvSize());
}
Also used : AesEaxKeyFormat(com.google.crypto.tink.proto.AesEaxKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 12 with KeyTemplate

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

the class AesGcmSivKeyManagerTest method testRawAes128GcmSivTemplate.

@Test
public void testRawAes128GcmSivTemplate() throws Exception {
    KeyTemplate template = AesGcmSivKeyManager.rawAes128GcmSivTemplate();
    assertEquals(new AesGcmSivKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
    AesGcmSivKeyFormat format = AesGcmSivKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(16, format.getKeySize());
}
Also used : AesGcmSivKeyFormat(com.google.crypto.tink.proto.AesGcmSivKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 13 with KeyTemplate

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

the class AesGcmSivKeyManagerTest method testRawAes256GcmSivTemplate.

@Test
public void testRawAes256GcmSivTemplate() throws Exception {
    KeyTemplate template = AesGcmSivKeyManager.rawAes256GcmSivTemplate();
    assertEquals(new AesGcmSivKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(KeyTemplate.OutputPrefixType.RAW, template.getOutputPrefixType());
    AesGcmSivKeyFormat format = AesGcmSivKeyFormat.parseFrom(ByteString.copyFrom(template.getValue()), ExtensionRegistryLite.getEmptyRegistry());
    assertEquals(32, format.getKeySize());
}
Also used : AesGcmSivKeyFormat(com.google.crypto.tink.proto.AesGcmSivKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 14 with KeyTemplate

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

the class RsaSsaPkcs1SignKeyManagerTest method testRawRsa4096SsaPkcs1Sha512F4Template.

@Test
public void testRawRsa4096SsaPkcs1Sha512F4Template() throws Exception {
    KeyTemplate template = RsaSsaPkcs1SignKeyManager.rawRsa4096SsaPkcs1Sha512F4Template();
    assertThat(template.getTypeUrl()).isEqualTo(new RsaSsaPkcs1SignKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.hasParams()).isTrue();
    assertThat(format.getParams().getHashType()).isEqualTo(HashType.SHA512);
    assertThat(format.getModulusSizeInBits()).isEqualTo(4096);
    assertThat(new BigInteger(1, format.getPublicExponent().toByteArray())).isEqualTo(BigInteger.valueOf(65537));
}
Also used : BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.KeyTemplate) RsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat) Test(org.junit.Test)

Example 15 with KeyTemplate

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

the class AesCtrHmacStreamingKeyManagerTest method testAes256CtrHmacSha2561MBTemplate.

@Test
public void testAes256CtrHmacSha2561MBTemplate() throws Exception {
    KeyTemplate template = AesCtrHmacStreamingKeyManager.aes256CtrHmacSha2561MBTemplate();
    assertThat(template.getTypeUrl()).isEqualTo(new AesCtrHmacStreamingKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    AesCtrHmacStreamingKeyFormat format = AesCtrHmacStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(32);
    assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
    assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getHmacParams().getHash()).isEqualTo(HashType.SHA256);
    assertThat(format.getParams().getHmacParams().getTagSize()).isEqualTo(32);
    assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(1 << 20);
}
Also used : AesCtrHmacStreamingKeyFormat(com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Aggregations

KeyTemplate (com.google.crypto.tink.KeyTemplate)143 Test (org.junit.Test)135 KeysetHandle (com.google.crypto.tink.KeysetHandle)56 ByteString (com.google.protobuf.ByteString)39 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)37 KeyData (com.google.crypto.tink.proto.KeyData)16 Keyset (com.google.crypto.tink.proto.Keyset)12 JsonObject (com.google.gson.JsonObject)8 KeysetManager (com.google.crypto.tink.KeysetManager)7 BigInteger (java.math.BigInteger)7 Instant (java.time.Instant)7 Aead (com.google.crypto.tink.Aead)6 Enums (com.google.crypto.tink.subtle.Enums)6 Clock (java.time.Clock)6 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)5 AesCtrHmacStreamingKeyFormat (com.google.crypto.tink.proto.AesCtrHmacStreamingKeyFormat)4 AesGcmHkdfStreamingKeyFormat (com.google.crypto.tink.proto.AesGcmHkdfStreamingKeyFormat)4 AesGcmKeyFormat (com.google.crypto.tink.proto.AesGcmKeyFormat)4 AesGcmSivKeyFormat (com.google.crypto.tink.proto.AesGcmSivKeyFormat)4 EciesAeadHkdfKeyFormat (com.google.crypto.tink.proto.EciesAeadHkdfKeyFormat)4