Search in sources :

Example 6 with HmacPrfKey

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

the class HmacPrfKeyManagerTest method createKey_checkValues.

@Test
public void createKey_checkValues() throws Exception {
    HmacPrfKeyFormat keyFormat = makeHmacPrfKeyFormat(16, HashType.SHA256);
    HmacPrfKey key = factory.createKey(keyFormat);
    assertThat(key.getKeyValue()).hasSize(keyFormat.getKeySize());
    assertThat(key.getParams().getHash()).isEqualTo(keyFormat.getParams().getHash());
}
Also used : HmacPrfKeyFormat(com.google.crypto.tink.proto.HmacPrfKeyFormat) HmacPrfKey(com.google.crypto.tink.proto.HmacPrfKey) Test(org.junit.Test)

Example 7 with HmacPrfKey

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

the class HmacPrfKeyManagerTest method validateKey_wrongVersion_throws.

@Test
public void validateKey_wrongVersion_throws() throws Exception {
    HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setVersion(1).build()));
}
Also used : HmacPrfKey(com.google.crypto.tink.proto.HmacPrfKey) Test(org.junit.Test)

Example 8 with HmacPrfKey

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

the class HmacPrfKeyManagerTest method validateKey_notValid_throws.

@Test
public void validateKey_notValid_throws() throws Exception {
    HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setKeyValue(ByteString.copyFrom(Random.randBytes(15))).build()));
    assertThrows(GeneralSecurityException.class, () -> manager.validateKey(HmacPrfKey.newBuilder(validKey).setParams(HmacPrfParams.newBuilder(validKey.getParams()).setHash(HashType.UNKNOWN_HASH).build()).build()));
}
Also used : HmacPrfKey(com.google.crypto.tink.proto.HmacPrfKey) Test(org.junit.Test)

Aggregations

HmacPrfKey (com.google.crypto.tink.proto.HmacPrfKey)8 Test (org.junit.Test)8 PrfHmacJce (com.google.crypto.tink.subtle.PrfHmacJce)3 SecretKeySpec (javax.crypto.spec.SecretKeySpec)3 HmacPrfParams (com.google.crypto.tink.proto.HmacPrfParams)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 HmacPrfKeyFormat (com.google.crypto.tink.proto.HmacPrfKeyFormat)1