Search in sources :

Example 1 with JwtHmacKeyFormat

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

the class JwtHmacKeyManagerTest method testHs384Template.

@Test
public void testHs384Template() throws Exception {
    KeyTemplate template = KeyTemplates.get("JWT_HS384");
    assertThat(template.getTypeUrl()).isEqualTo(new JwtHmacKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
    JwtHmacKeyFormat format = JwtHmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(48);
    assertThat(format.getAlgorithm()).isEqualTo(JwtHmacAlgorithm.HS384);
}
Also used : JwtHmacKeyFormat(com.google.crypto.tink.proto.JwtHmacKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 2 with JwtHmacKeyFormat

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

the class JwtHmacKeyManagerTest method testHs512Template.

@Test
public void testHs512Template() throws Exception {
    KeyTemplate template = KeyTemplates.get("JWT_HS512");
    assertThat(template.getTypeUrl()).isEqualTo(new JwtHmacKeyManager().getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.TINK);
    JwtHmacKeyFormat format = JwtHmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(64);
    assertThat(format.getAlgorithm()).isEqualTo(JwtHmacAlgorithm.HS512);
}
Also used : JwtHmacKeyFormat(com.google.crypto.tink.proto.JwtHmacKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 3 with JwtHmacKeyFormat

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

the class JwtHmacKeyManagerTest method testRawHs256Template.

@Test
public void testRawHs256Template() throws Exception {
    KeyTemplate template = KeyTemplates.get("JWT_HS256_RAW");
    assertThat(template.getTypeUrl()).isEqualTo(manager.getKeyType());
    assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
    JwtHmacKeyFormat format = JwtHmacKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
    assertThat(format.getKeySize()).isEqualTo(32);
    assertThat(format.getAlgorithm()).isEqualTo(JwtHmacAlgorithm.HS256);
}
Also used : JwtHmacKeyFormat(com.google.crypto.tink.proto.JwtHmacKeyFormat) KeyTemplate(com.google.crypto.tink.KeyTemplate) Test(org.junit.Test)

Example 4 with JwtHmacKeyFormat

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

the class JwtHmacKeyManagerTest method createKey_multipleTimes.

@Test
public void createKey_multipleTimes() throws Exception {
    JwtHmacKeyFormat keyFormat = makeJwtHmacKeyFormat(32, JwtHmacAlgorithm.HS256);
    int numKeys = 100;
    Set<String> keys = new TreeSet<>();
    for (int i = 0; i < numKeys; ++i) {
        keys.add(TestUtil.hexEncode(factory.createKey(keyFormat).getKeyValue().toByteArray()));
    }
    assertThat(keys).hasSize(numKeys);
}
Also used : JwtHmacKeyFormat(com.google.crypto.tink.proto.JwtHmacKeyFormat) TreeSet(java.util.TreeSet) ByteString(com.google.protobuf.ByteString) DataPoint(org.junit.experimental.theories.DataPoint) Test(org.junit.Test)

Example 5 with JwtHmacKeyFormat

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

the class JwtHmacKeyManagerTest method createKey_checkValues.

@Test
public void createKey_checkValues() throws Exception {
    JwtHmacKeyFormat keyFormat = makeJwtHmacKeyFormat(32, JwtHmacAlgorithm.HS256);
    JwtHmacKey key = factory.createKey(keyFormat);
    assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
    assertThat(key.getAlgorithm()).isEqualTo(keyFormat.getAlgorithm());
}
Also used : JwtHmacKeyFormat(com.google.crypto.tink.proto.JwtHmacKeyFormat) JwtHmacKey(com.google.crypto.tink.proto.JwtHmacKey) Test(org.junit.Test)

Aggregations

JwtHmacKeyFormat (com.google.crypto.tink.proto.JwtHmacKeyFormat)6 Test (org.junit.Test)6 KeyTemplate (com.google.crypto.tink.KeyTemplate)4 JwtHmacKey (com.google.crypto.tink.proto.JwtHmacKey)1 ByteString (com.google.protobuf.ByteString)1 TreeSet (java.util.TreeSet)1 DataPoint (org.junit.experimental.theories.DataPoint)1