use of com.couchbase.client.core.encryption.CryptoManager in project spring-data-couchbase by spring-projects.
the class AbstractCouchbaseConfiguration method couchbaseObjectMapper.
/**
* Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
*
* @return ObjectMapper
*/
public ObjectMapper couchbaseObjectMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JsonValueModule());
CryptoManager cryptoManager = null;
if (cryptoManager != null) {
mapper.registerModule(new EncryptionModule(cryptoManager));
}
return mapper;
}
use of com.couchbase.client.core.encryption.CryptoManager in project java-couchbase-encryption by couchbase.
the class AeadAes256CbcHmacSha512ProviderTest method encryptAndDecrypt.
@Test
void encryptAndDecrypt() throws Exception {
final byte[] plaintext = "\"The enemy knows the system.\"".getBytes(UTF_8);
final Map<String, Object> encrypted = mapOf("alg", "AEAD_AES_256_CBC_HMAC_SHA512", "kid", "test-key", "ciphertext", "GvOMLcK5b/3YZpQJI0G8BLm98oj20ZLdqKDV3MfTuGlWL4R5p5Deykuv2XLW4LcDvnOkmhuUSRbQ8QVEmbjq43XHdOm3ColJ6LzoaAtJihk=");
AeadAes256CbcHmacSha512Provider provider = EncryptionTestHelper.provider();
CryptoManager cryptoManager = DefaultCryptoManager.builder().decrypter(provider.decrypter()).defaultEncrypter(provider.encrypterForKey("test-key")).build();
assertEquals(encrypted, cryptoManager.encrypt(plaintext, null));
assertArrayEquals(plaintext, cryptoManager.decrypt(encrypted));
}
use of com.couchbase.client.core.encryption.CryptoManager in project java-couchbase-encryption by couchbase.
the class LegacyAesDecrypterTest method canDecrypt.
@Test
void canDecrypt() {
Map<String, byte[]> keys = new HashMap<>();
keys.put("aes256Key", fakeKey(32));
keys.put("aes128Key", fakeKey(16));
keys.put("hmacKey", fakeKey(7));
Keyring keyring = Keyring.fromMap(keys);
// Generated by Java FLE version 1
JsonObject obj = JsonObject.fromJson("{\n" + " \"__crypt_one\": {\n" + " \"sig\": \"TkpyZnha4xd+FsX1aEGqB235d495oOUBfC4Y+Gbic4U=\",\n" + " \"ciphertext\": \"MZI/xSiM7919UTM5CO/RWg==\",\n" + " \"alg\": \"AES-128-HMAC-SHA256\",\n" + " \"iv\": \"HIBdmnoQD4DUgkBj5LAMFw==\",\n" + " \"kid\": \"aes128Key\"\n" + " },\n" + " \"__crypt_two\": {\n" + " \"sig\": \"f0hWVdBM/pEcADl0eKx8Eq/KhP00/2oqXYXTJkt2xhA=\",\n" + " \"ciphertext\": \"biERBQajaRxrfe8mXFqJag==\",\n" + " \"alg\": \"AES-256-HMAC-SHA256\",\n" + " \"iv\": \"03AUmzwQqnbs/JhkWGrIkw==\",\n" + " \"kid\": \"aes256Key\"\n" + " }\n" + "}");
CryptoManager cryptoManager = DefaultCryptoManager.builder().encryptedFieldNamePrefix("__crypt_").legacyAesDecrypters(keyring, keyName -> "hmacKey").build();
JsonObjectCrypto crypto = obj.crypto(cryptoManager);
assertEquals(1, crypto.getInt("one"));
assertEquals(2, crypto.getInt("two"));
}
Aggregations