use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetHandleTest method toString_containsNoKeyMaterial.
@Test
public void toString_containsNoKeyMaterial() throws Exception {
String keyValue = "01234567890123456";
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes(UTF_8), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
KeysetHandle handle = KeysetHandle.fromKeyset(keyset);
String keysetInfo = handle.toString();
expect.that(keysetInfo).doesNotContain(keyValue);
expect.that(handle.getKeyset().toString()).contains(keyValue);
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetHandleTest method readNoSecret_withTypeSymmetric_shouldThrow.
@Test
public void readNoSecret_withTypeSymmetric_shouldThrow() throws Exception {
String keyValue = "01234567890123456";
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes(UTF_8), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
assertThrows(GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(keyset.toByteArray()));
assertThrows(GeneralSecurityException.class, () -> KeysetHandle.readNoSecret(BinaryKeysetReader.withBytes(keyset.toByteArray())));
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetHandleTest method writeNoSecret_withTypeSymmetric_shouldThrow.
@Test
public void writeNoSecret_withTypeSymmetric_shouldThrow() throws Exception {
String keyValue = "01234567890123456";
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(TestUtil.createHmacKeyData(keyValue.getBytes(UTF_8), 16), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK));
KeysetHandle handle = KeysetHandle.fromKeyset(keyset);
assertThrows(GeneralSecurityException.class, () -> handle.writeNoSecret(/* writer= */
null));
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetHandleTest method getPrimitive_wrappingDoneCorrectly.
// Tests that getPrimitive does correct wrapping and not just return the primary. For this, we
// simply add a raw, non-primary key and encrypt directly with it.
@Test
public void getPrimitive_wrappingDoneCorrectly() throws Exception {
KeyData rawKeyData = Registry.newKeyData(KeyTemplates.get("AES128_EAX"));
Keyset keyset = TestUtil.createKeyset(TestUtil.createKey(Registry.newKeyData(KeyTemplates.get("AES128_EAX").getProto()), 42, KeyStatusType.ENABLED, OutputPrefixType.TINK), TestUtil.createKey(rawKeyData, 43, KeyStatusType.ENABLED, OutputPrefixType.RAW));
KeysetHandle handle = KeysetHandle.fromKeyset(keyset);
byte[] message = Random.randBytes(20);
byte[] aad = Random.randBytes(20);
Aead aeadToEncrypt = Registry.getPrimitive(rawKeyData, Aead.class);
Aead aead = handle.getPrimitive(Aead.class);
assertThat(aead.decrypt(aeadToEncrypt.encrypt(message, aad), aad)).isEqualTo(message);
}
use of com.google.crypto.tink.proto.Keyset in project tink by google.
the class KeysetHandleTest method readNoSecret_shouldWork.
@Test
public void readNoSecret_shouldWork() throws Exception {
KeysetHandle privateHandle = KeysetHandle.generateNew(SignatureKeyTemplates.ECDSA_P256);
Keyset keyset = privateHandle.getPublicKeysetHandle().getKeyset();
Keyset keyset2 = KeysetHandle.readNoSecret(keyset.toByteArray()).getKeyset();
Keyset keyset3 = KeysetHandle.readNoSecret(BinaryKeysetReader.withBytes(keyset.toByteArray())).getKeyset();
expect.that(keyset).isEqualTo(keyset2);
expect.that(keyset).isEqualTo(keyset3);
}
Aggregations