Search in sources :

Example 46 with KeyTemplate

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

the class SignatureKeyTemplatesTest method rsaSsaPkcs1_3072.

@Test
public void rsaSsaPkcs1_3072() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.RSA_SSA_PKCS1_3072_SHA256_F4;
    assertEquals(new RsaSsaPkcs1SignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    RsaSsaPkcs1KeyFormat format = RsaSsaPkcs1KeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertEquals(HashType.SHA256, format.getParams().getHashType());
    assertEquals(3072, format.getModulusSizeInBits());
    assertEquals(BigInteger.valueOf(65537), new BigInteger(1, format.getPublicExponent().toByteArray()));
}
Also used : BigInteger(java.math.BigInteger) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) RsaSsaPkcs1KeyFormat(com.google.crypto.tink.proto.RsaSsaPkcs1KeyFormat) Test(org.junit.Test)

Example 47 with KeyTemplate

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

the class SignatureKeyTemplatesTest method ecdsaP256IeeeWithoutPrefix.

@Test
public void ecdsaP256IeeeWithoutPrefix() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.ECDSA_P256_IEEE_P1363_WITHOUT_PREFIX;
    assertEquals(new EcdsaSignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.RAW, template.getOutputPrefixType());
    EcdsaKeyFormat format = EcdsaKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertEquals(HashType.SHA256, format.getParams().getHashType());
    assertEquals(EllipticCurveType.NIST_P256, format.getParams().getCurve());
    assertEquals(EcdsaSignatureEncoding.IEEE_P1363, format.getParams().getEncoding());
}
Also used : EcdsaKeyFormat(com.google.crypto.tink.proto.EcdsaKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 48 with KeyTemplate

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

the class SignatureKeyTemplatesTest method ecdsaP384.

@Test
public void ecdsaP384() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.ECDSA_P384;
    assertEquals(new EcdsaSignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    EcdsaKeyFormat format = EcdsaKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertEquals(HashType.SHA512, format.getParams().getHashType());
    assertEquals(EllipticCurveType.NIST_P384, format.getParams().getCurve());
    assertEquals(EcdsaSignatureEncoding.DER, format.getParams().getEncoding());
}
Also used : EcdsaKeyFormat(com.google.crypto.tink.proto.EcdsaKeyFormat) KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 49 with KeyTemplate

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

the class SignatureKeyTemplatesTest method ed25519.

@Test
public void ed25519() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.ED25519;
    assertEquals(new Ed25519PrivateKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    // Empty format.
    assertTrue(template.getValue().isEmpty());
}
Also used : KeyTemplate(com.google.crypto.tink.proto.KeyTemplate) Test(org.junit.Test)

Example 50 with KeyTemplate

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

the class SignatureKeyTemplatesTest method rsaSsaPss3072.

@Test
public void rsaSsaPss3072() throws Exception {
    KeyTemplate template = SignatureKeyTemplates.RSA_SSA_PSS_3072_SHA256_SHA256_32_F4;
    assertEquals(new RsaSsaPssSignKeyManager().getKeyType(), template.getTypeUrl());
    assertEquals(OutputPrefixType.TINK, template.getOutputPrefixType());
    RsaSsaPssKeyFormat format = RsaSsaPssKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertTrue(format.hasParams());
    assertEquals(HashType.SHA256, format.getParams().getSigHash());
    assertEquals(HashType.SHA256, format.getParams().getMgf1Hash());
    assertEquals(32, format.getParams().getSaltLength());
    assertEquals(3072, format.getModulusSizeInBits());
    assertEquals(BigInteger.valueOf(65537), new BigInteger(1, format.getPublicExponent().toByteArray()));
}
Also used : RsaSsaPssKeyFormat(com.google.crypto.tink.proto.RsaSsaPssKeyFormat) BigInteger(java.math.BigInteger) 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