Search in sources :

Example 6 with JwtHmacKey

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

the class JwtHmacKeyManagerTest method getRfc7515ExampleKeysetHandle.

private static KeysetHandle getRfc7515ExampleKeysetHandle() throws Exception {
    String keyValue = "AyM1SysPpbyDfgZld3umj1qzKObwVMkoqQ-EstJQLr_T-1qS0gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr1Z9CAow";
    JwtHmacKey key = JwtHmacKey.newBuilder().setVersion(0).setAlgorithm(JwtHmacAlgorithm.HS256).setKeyValue(ByteString.copyFrom(Base64.urlSafeDecode(keyValue))).build();
    KeyData keyData = KeyData.newBuilder().setTypeUrl("type.googleapis.com/google.crypto.tink.JwtHmacKey").setValue(key.toByteString()).setKeyMaterialType(KeyData.KeyMaterialType.SYMMETRIC).build();
    Keyset.Key keySetKey = Keyset.Key.newBuilder().setKeyData(keyData).setKeyId(123).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(OutputPrefixType.RAW).build();
    Keyset keyset = Keyset.newBuilder().addKey(keySetKey).setPrimaryKeyId(123).build();
    return CleartextKeysetHandle.fromKeyset(keyset);
}
Also used : Keyset(com.google.crypto.tink.proto.Keyset) JwtHmacKey(com.google.crypto.tink.proto.JwtHmacKey) ByteString(com.google.protobuf.ByteString) KeyData(com.google.crypto.tink.proto.KeyData)

Example 7 with JwtHmacKey

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

the class JwtHmacKeyManagerTest method validateKey_wrongVersion_throws.

@Test
public void validateKey_wrongVersion_throws() throws Exception {
    JwtHmacKey validKey = factory.createKey(makeJwtHmacKeyFormat(32, JwtHmacAlgorithm.HS256));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(JwtHmacKey.newBuilder(validKey).setVersion(1).build()));
}
Also used : JwtHmacKey(com.google.crypto.tink.proto.JwtHmacKey) Test(org.junit.Test)

Example 8 with JwtHmacKey

use of com.google.crypto.tink.proto.JwtHmacKey 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

JwtHmacKey (com.google.crypto.tink.proto.JwtHmacKey)8 Test (org.junit.Test)6 Keyset (com.google.crypto.tink.proto.Keyset)5 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)3 KeyTemplate (com.google.crypto.tink.KeyTemplate)3 KeysetHandle (com.google.crypto.tink.KeysetHandle)3 KeyData (com.google.crypto.tink.proto.KeyData)3 ByteString (com.google.protobuf.ByteString)3 PrfHmacJce (com.google.crypto.tink.subtle.PrfHmacJce)2 PrfMac (com.google.crypto.tink.subtle.PrfMac)2 JsonObject (com.google.gson.JsonObject)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 JwtHmacKeyFormat (com.google.crypto.tink.proto.JwtHmacKeyFormat)1