Search in sources :

Example 6 with PrfHmacJce

use of com.google.crypto.tink.subtle.PrfHmacJce in project tink by google.

the class HmacKeyManagerTest method getPrimitive_worksForSha1.

@Test
public void getPrimitive_worksForSha1() throws Exception {
    HmacKey validKey = factory.createKey(makeHmacKeyFormat(16, 19, HashType.SHA1));
    Mac managerMac = manager.getPrimitive(validKey, Mac.class);
    Mac directMac = new PrfMac(new PrfHmacJce("HMACSHA1", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC")), 19);
    byte[] message = Random.randBytes(50);
    managerMac.verifyMac(directMac.computeMac(message), message);
}
Also used : PrfMac(com.google.crypto.tink.subtle.PrfMac) SecretKeySpec(javax.crypto.spec.SecretKeySpec) PrfHmacJce(com.google.crypto.tink.subtle.PrfHmacJce) HmacKey(com.google.crypto.tink.proto.HmacKey) Mac(com.google.crypto.tink.Mac) PrfMac(com.google.crypto.tink.subtle.PrfMac) Test(org.junit.Test)

Example 7 with PrfHmacJce

use of com.google.crypto.tink.subtle.PrfHmacJce in project tink by google.

the class HmacKeyManagerTest method getPrimitive_worksForSha256.

@Test
public void getPrimitive_worksForSha256() throws Exception {
    HmacKey validKey = factory.createKey(makeHmacKeyFormat(16, 29, HashType.SHA256));
    Mac managerMac = manager.getPrimitive(validKey, Mac.class);
    Mac directMac = new PrfMac(new PrfHmacJce("HMACSHA256", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC")), 29);
    byte[] message = Random.randBytes(50);
    managerMac.verifyMac(directMac.computeMac(message), message);
}
Also used : PrfMac(com.google.crypto.tink.subtle.PrfMac) SecretKeySpec(javax.crypto.spec.SecretKeySpec) PrfHmacJce(com.google.crypto.tink.subtle.PrfHmacJce) HmacKey(com.google.crypto.tink.proto.HmacKey) Mac(com.google.crypto.tink.Mac) PrfMac(com.google.crypto.tink.subtle.PrfMac) Test(org.junit.Test)

Example 8 with PrfHmacJce

use of com.google.crypto.tink.subtle.PrfHmacJce in project tink by google.

the class HmacPrfKeyManagerTest method getPrimitive_worksForSha1.

@Test
public void getPrimitive_worksForSha1() throws Exception {
    HmacPrfKey validKey = factory.createKey(makeHmacPrfKeyFormat(16, HashType.SHA1));
    Prf managerPrf = manager.getPrimitive(validKey, Prf.class);
    Prf directPrf = new PrfHmacJce("HMACSHA1", new SecretKeySpec(validKey.getKeyValue().toByteArray(), "HMAC"));
    byte[] message = Random.randBytes(50);
    assertThat(managerPrf.compute(message, 19)).isEqualTo(directPrf.compute(message, 19));
}
Also used : SecretKeySpec(javax.crypto.spec.SecretKeySpec) PrfHmacJce(com.google.crypto.tink.subtle.PrfHmacJce) HmacPrfKey(com.google.crypto.tink.proto.HmacPrfKey) Test(org.junit.Test)

Aggregations

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