use of com.couchbase.client.encryption.Keyring 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