Search in sources :

Example 6 with PrfMac

use of com.google.crypto.tink.subtle.PrfMac 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)

Aggregations

PrfMac (com.google.crypto.tink.subtle.PrfMac)6 Test (org.junit.Test)6 PrfHmacJce (com.google.crypto.tink.subtle.PrfHmacJce)5 SecretKeySpec (javax.crypto.spec.SecretKeySpec)5 Mac (com.google.crypto.tink.Mac)4 HmacKey (com.google.crypto.tink.proto.HmacKey)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 AesCmacKey (com.google.crypto.tink.proto.AesCmacKey)1 PrfAesCmac (com.google.crypto.tink.subtle.PrfAesCmac)1