Search in sources :

Example 1 with StreamingPrf

use of com.google.crypto.tink.subtle.prf.StreamingPrf in project tink by google.

the class HkdfPrfKeyManagerTest method createPrimitive_works.

@Test
public void createPrimitive_works() throws Exception {
    HkdfPrfKey key = HkdfPrfKey.newBuilder().setKeyValue(ByteString.copyFromUtf8("super secret key value")).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFromUtf8("some salt")).setHash(HashType.SHA256)).build();
    StreamingPrf managerPrf = manager.getPrimitive(key, StreamingPrf.class);
    InputStream managerInput = managerPrf.computePrf("my input".getBytes(UTF_8));
    byte[] managerOutput = new byte[10];
    assertThat(managerInput.read(managerOutput)).isEqualTo(10);
    HkdfStreamingPrf directPrf = new HkdfStreamingPrf(Enums.HashType.SHA256, "super secret key value".getBytes(UTF_8), "some salt".getBytes(UTF_8));
    InputStream directInput = directPrf.computePrf("my input".getBytes(UTF_8));
    byte[] directOutput = new byte[10];
    assertThat(directInput.read(directOutput)).isEqualTo(10);
    assertThat(directOutput).isEqualTo(managerOutput);
}
Also used : HkdfStreamingPrf(com.google.crypto.tink.subtle.prf.HkdfStreamingPrf) StreamingPrf(com.google.crypto.tink.subtle.prf.StreamingPrf) HkdfStreamingPrf(com.google.crypto.tink.subtle.prf.HkdfStreamingPrf) InputStream(java.io.InputStream) HkdfPrfKey(com.google.crypto.tink.proto.HkdfPrfKey) Test(org.junit.Test)

Aggregations

HkdfPrfKey (com.google.crypto.tink.proto.HkdfPrfKey)1 HkdfStreamingPrf (com.google.crypto.tink.subtle.prf.HkdfStreamingPrf)1 StreamingPrf (com.google.crypto.tink.subtle.prf.StreamingPrf)1 InputStream (java.io.InputStream)1 Test (org.junit.Test)1