use of com.google.crypto.tink.subtle.prf.HkdfStreamingPrf 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);
}
Aggregations