use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.
the class AsymmetricTestingServicesTest method hybridDecrypt_failsOnBadKeyset.
@Test
public void hybridDecrypt_failsOnBadKeyset() throws Exception {
byte[] template = KeyTemplateProtoConverter.toByteArray(EciesAeadHkdfPrivateKeyManager.eciesP256HkdfHmacSha256Aes128GcmTemplate());
byte[] plaintext = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
byte[] contextInfo = "hybrid_decrypt_bad_keyset".getBytes(UTF_8);
KeysetGenerateResponse privateKeysetResponse = generateKeyset(keysetStub, template);
assertThat(privateKeysetResponse.getErr()).isEmpty();
byte[] privateKeyset = privateKeysetResponse.getKeyset().toByteArray();
KeysetPublicResponse pubResponse = publicKeyset(keysetStub, privateKeyset);
assertThat(pubResponse.getErr()).isEmpty();
byte[] publicKeyset = pubResponse.getPublicKeyset().toByteArray();
HybridEncryptResponse encResponse = hybridEncrypt(hybridStub, publicKeyset, plaintext, contextInfo);
assertThat(encResponse.getErr()).isEmpty();
byte[] ciphertext = encResponse.getCiphertext().toByteArray();
byte[] badKeyset = "bad keyset".getBytes(UTF_8);
HybridDecryptResponse decResponse = hybridDecrypt(hybridStub, badKeyset, ciphertext, contextInfo);
assertThat(decResponse.getErr()).isNotEmpty();
}
use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.
the class AsymmetricTestingServicesTest method signatureSignVerify_success.
@Test
public void signatureSignVerify_success() throws Exception {
byte[] template = KeyTemplateProtoConverter.toByteArray(EcdsaSignKeyManager.ecdsaP256Template());
byte[] data = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
KeysetGenerateResponse genResponse = generateKeyset(keysetStub, template);
assertThat(genResponse.getErr()).isEmpty();
byte[] privateKeyset = genResponse.getKeyset().toByteArray();
KeysetPublicResponse pubResponse = publicKeyset(keysetStub, privateKeyset);
assertThat(pubResponse.getErr()).isEmpty();
byte[] publicKeyset = pubResponse.getPublicKeyset().toByteArray();
SignatureSignResponse signResponse = signatureSign(signatureStub, privateKeyset, data);
assertThat(signResponse.getErr()).isEmpty();
byte[] signature = signResponse.getSignature().toByteArray();
SignatureVerifyResponse verifyResponse = signatureVerify(signatureStub, publicKeyset, signature, data);
assertThat(verifyResponse.getErr()).isEmpty();
}
use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.
the class TestingServicesTest method daeadDecryptDeterministically_failsOnBadCiphertext.
@Test
public void daeadDecryptDeterministically_failsOnBadCiphertext() throws Exception {
byte[] template = KeyTemplateProtoConverter.toByteArray(AesSivKeyManager.aes256SivTemplate());
byte[] badCiphertext = "bad ciphertext".getBytes(UTF_8);
byte[] associatedData = "aead_decrypt_fails_on_bad_ciphertext".getBytes(UTF_8);
KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
assertThat(keysetResponse.getErr()).isEmpty();
byte[] keyset = keysetResponse.getKeyset().toByteArray();
DeterministicAeadDecryptResponse decResponse = daeadDecrypt(daeadStub, keyset, badCiphertext, associatedData);
assertThat(decResponse.getErr()).isNotEmpty();
}
use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.
the class TestingServicesTest method daeadGenerateEncryptDecryptDeterministically_success.
@Test
public void daeadGenerateEncryptDecryptDeterministically_success() throws Exception {
byte[] template = KeyTemplateProtoConverter.toByteArray(AesSivKeyManager.aes256SivTemplate());
byte[] plaintext = "The quick brown fox jumps over the lazy dog".getBytes(UTF_8);
byte[] associatedData = "generate_encrypt_decrypt".getBytes(UTF_8);
KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
assertThat(keysetResponse.getErr()).isEmpty();
byte[] keyset = keysetResponse.getKeyset().toByteArray();
DeterministicAeadEncryptResponse encResponse = daeadEncrypt(daeadStub, keyset, plaintext, associatedData);
assertThat(encResponse.getErr()).isEmpty();
byte[] ciphertext = encResponse.getCiphertext().toByteArray();
DeterministicAeadDecryptResponse decResponse = daeadDecrypt(daeadStub, keyset, ciphertext, associatedData);
assertThat(decResponse.getErr()).isEmpty();
byte[] output = decResponse.getPlaintext().toByteArray();
assertThat(output).isEqualTo(plaintext);
}
use of com.google.crypto.tink.proto.testing.KeysetGenerateResponse in project tink by google.
the class TestingServicesTest method streamingAeadDecrypt_failsOnBadCiphertext.
@Test
public void streamingAeadDecrypt_failsOnBadCiphertext() throws Exception {
byte[] template = KeyTemplateProtoConverter.toByteArray(AesGcmHkdfStreamingKeyManager.aes128GcmHkdf4KBTemplate());
byte[] badCiphertext = "bad ciphertext".getBytes(UTF_8);
byte[] associatedData = "streamingAead_decrypt_fails_on_bad_ciphertext".getBytes(UTF_8);
KeysetGenerateResponse keysetResponse = generateKeyset(keysetStub, template);
assertThat(keysetResponse.getErr()).isEmpty();
byte[] keyset = keysetResponse.getKeyset().toByteArray();
StreamingAeadDecryptResponse decResponse = streamingAeadDecrypt(streamingAeadStub, keyset, badCiphertext, associatedData);
assertThat(decResponse.getErr()).isNotEmpty();
}
Aggregations