use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes128GcmHkdf4KBTemplate.
@Test
public void testAes128GcmHkdf4KBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes128GcmHkdf4KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(16);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(16);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes256GcmHkdf4KBTemplate.
@Test
public void testAes256GcmHkdf4KBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes256GcmHkdf4KBTemplate();
assertThat(template.getTypeUrl()).isEqualTo(new AesGcmHkdfStreamingKeyManager().getKeyType());
assertThat(template.getOutputPrefixType()).isEqualTo(KeyTemplate.OutputPrefixType.RAW);
AesGcmHkdfStreamingKeyFormat format = AesGcmHkdfStreamingKeyFormat.parseFrom(template.getValue(), ExtensionRegistryLite.getEmptyRegistry());
assertThat(format.getKeySize()).isEqualTo(32);
assertThat(format.getParams().getDerivedKeySize()).isEqualTo(32);
assertThat(format.getParams().getHkdfHashType()).isEqualTo(HashType.SHA256);
assertThat(format.getParams().getCiphertextSegmentSize()).isEqualTo(4096);
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeyHandleTest method createFromKey_keyDataUnknown_shouldHaveSecret.
@Test
public void createFromKey_keyDataUnknown_shouldHaveSecret() throws Exception {
KeyTemplate kt = KeyTemplates.get("ED25519");
KeyData kd = KeyData.newBuilder().mergeFrom(Registry.newKeyData(kt)).setKeyMaterialType(KeyData.KeyMaterialType.UNKNOWN_KEYMATERIAL).build();
KeyHandle kh = KeyHandle.createFromKey(kd, kt.getOutputPrefixType());
assertThat(kh.hasSecret()).isTrue();
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeyHandleTest method generateNew_generatesDifferentKeys.
@Test
public void generateNew_generatesDifferentKeys() throws Exception {
KeyTemplate template = KeyTemplates.get("AES128_EAX");
Set<String> keys = new TreeSet<>();
int numKeys = 2;
for (int j = 0; j < numKeys; j++) {
KeyHandle handle = KeyHandle.generateNew(template);
ProtoKey protoKey = (ProtoKey) handle.getKey(SecretKeyAccess.insecureSecretAccess());
KeyData keyData = protoKey.getProtoKey();
AesEaxKey aesEaxKey = AesEaxKey.parseFrom(keyData.getValue(), ExtensionRegistryLite.getEmptyRegistry());
keys.add(aesEaxKey.getKeyValue().toStringUtf8());
}
assertThat(keys).hasSize(numKeys);
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeyHandleTest method createFromKey_keyDataAsymmetricPrivate_shouldHaveSecret.
@Test
public void createFromKey_keyDataAsymmetricPrivate_shouldHaveSecret() throws Exception {
KeyTemplate kt = KeyTemplates.get("ED25519");
KeyData kd = Registry.newKeyData(kt);
KeyHandle kh = KeyHandle.createFromKey(kd, kt.getOutputPrefixType());
assertThat(kh.hasSecret()).isTrue();
}
Aggregations