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);
}
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);
}
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);
}
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);
}
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());
}
Aggregations