use of com.google.crypto.tink.proto.HkdfPrfKey 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);
}
use of com.google.crypto.tink.proto.HkdfPrfKey in project tink by google.
the class HkdfPrfKeyManagerTest method validateKey_empty_throws.
@Test
public void validateKey_empty_throws() throws Exception {
HkdfPrfKey key = HkdfPrfKey.getDefaultInstance();
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(key));
}
use of com.google.crypto.tink.proto.HkdfPrfKey in project tink by google.
the class HkdfPrfKeyManagerTest method validateKey_invalid31ByteKey_throws.
@Test
public void validateKey_invalid31ByteKey_throws() throws Exception {
HkdfPrfKey key = HkdfPrfKey.newBuilder().setVersion(0).setKeyValue(ByteString.copyFrom(Random.randBytes(31))).setParams(HkdfPrfParams.newBuilder().setHash(HashType.SHA256)).build();
assertThrows(GeneralSecurityException.class, () -> manager.validateKey(key));
}
use of com.google.crypto.tink.proto.HkdfPrfKey in project tink by google.
the class HkdfPrfKeyManagerTest method createKey_valuesAreOk.
@Test
public void createKey_valuesAreOk() throws Exception {
HkdfPrfKeyFormat format = HkdfPrfKeyFormat.newBuilder().setKeySize(77).setParams(HkdfPrfParams.newBuilder().setSalt(ByteString.copyFrom(Random.randBytes(5))).setHash(HashType.SHA256)).build();
HkdfPrfKey key = factory.createKey(format);
assertThat(key.getVersion()).isEqualTo(0);
assertThat(key.getKeyValue()).hasSize(77);
assertThat(key.getParams()).isEqualTo(format.getParams());
}
use of com.google.crypto.tink.proto.HkdfPrfKey in project tink by google.
the class HkdfPrfKeyManagerTest method createPrfSetPrimitive_works.
/**
* Smoke test getPrimitive for PrfSet via the HkdfPrfKeymanager.
*/
@Test
public void createPrfSetPrimitive_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();
manager.getPrimitive(key, Prf.class);
}
Aggregations