use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class AesGcmHkdfStreamingKeyManagerTest method testAes256GcmHkdf1MBTemplate.
@Test
public void testAes256GcmHkdf1MBTemplate() throws Exception {
KeyTemplate template = AesGcmHkdfStreamingKeyManager.aes256GcmHkdf1MBTemplate();
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(1 << 20);
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeysetServiceImpl method generate.
@Override
public void generate(KeysetGenerateRequest request, StreamObserver<KeysetGenerateResponse> responseObserver) {
KeysetGenerateResponse response;
try {
KeyTemplate template = KeyTemplateProtoConverter.fromByteArray(request.getTemplate().toByteArray());
KeysetHandle keysetHandle = KeysetHandle.generateNew(template);
Keyset keyset = CleartextKeysetHandle.getKeyset(keysetHandle);
ByteArrayOutputStream keysetStream = new ByteArrayOutputStream();
BinaryKeysetWriter.withOutputStream(keysetStream).write(keyset);
keysetStream.close();
response = KeysetGenerateResponse.newBuilder().setKeyset(ByteString.copyFrom(keysetStream.toByteArray())).build();
} catch (GeneralSecurityException e) {
response = KeysetGenerateResponse.newBuilder().setErr(e.toString()).build();
} catch (IOException e) {
responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
return;
}
responseObserver.onNext(response);
responseObserver.onCompleted();
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeysetServiceImpl method getTemplate.
@Override
public void getTemplate(KeysetTemplateRequest request, StreamObserver<KeysetTemplateResponse> responseObserver) {
KeysetTemplateResponse response;
try {
KeyTemplate template = KeyTemplates.get(request.getTemplateName());
response = KeysetTemplateResponse.newBuilder().setKeyTemplate(ByteString.copyFrom(KeyTemplateProtoConverter.toByteArray(template))).build();
} catch (GeneralSecurityException e) {
response = KeysetTemplateResponse.newBuilder().setErr(e.toString()).build();
}
responseObserver.onNext(response);
responseObserver.onCompleted();
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class TestingServicesTest method template_success.
@Test
public void template_success() throws Exception {
KeysetTemplateRequest request = KeysetTemplateRequest.newBuilder().setTemplateName("AES256_GCM").build();
KeysetTemplateResponse response = keysetStub.getTemplate(request);
assertThat(response.getErr()).isEmpty();
KeyTemplate template = KeyTemplateProtoConverter.fromByteArray(response.getKeyTemplate().toByteArray());
assertThat(template.getTypeUrl()).isEqualTo("type.googleapis.com/google.crypto.tink.AesGcmKey");
}
use of com.google.crypto.tink.KeyTemplate in project tink by google.
the class KeyHandleTest method createFromKey_keyDataAsymmetricPublic_shouldNotHaveSecret.
@Test
public void createFromKey_keyDataAsymmetricPublic_shouldNotHaveSecret() throws Exception {
KeyTemplate kt = KeyTemplates.get("ED25519");
KeyData kd = Registry.getPublicKeyData(kt.getTypeUrl(), Registry.newKeyData(kt).getValue());
KeyHandle kh = KeyHandle.createFromKey(kd, kt.getOutputPrefixType());
assertThat(kh.hasSecret()).isFalse();
}
Aggregations