Writing Encrypted Arrays

To write to an encrypted array, you simply need to open it for writing using the encryption key you used to create it.

C
C++
Python
R
Java
Go
C
// ... create context ctx
// Open encrypted array for writing
const char key[] = "0123456789abcdeF0123456789abcdeF";
tiledb_array_t* array;
tiledb_array_alloc(ctx, "<array-uri>", &array);
tiledb_array_open_with_key(
ctx, array, TILEDB_WRITE, TILEDB_AES_256_GCM, key, sizeof(key));
C++
// ... create context ctx
// Open encrypted array for writing
const char key[] = "0123456789abcdeF0123456789abcdeF";
Array array(ctx, "<array-uri>", TILEDB_WRITE, TILEDB_AES_256_GCM, key, sizeof(key));
Python
key = "0123456789abcdeF0123456789abcdeF"
tiledb.SparseArray.create(array_name, schema, key=key)
with tiledb.SparseArray(array_name, 'w', key=key) as A:
# A[] = ...
with tiledb.SparseArray(array_name, key=key) as A:
# read A[...]
R
ctx <- tiledb_ctx()
arrptr <- tiledb:::libtiledb_array_open_with_key(ctx@ptr, uridensewkey,
"WRITE", encryption_key)
## data: simple (integer sequence) of 1:16 times 10
vec <- 1:16 * 10L
subarr <- c(1L,4L, 1L,4L)
qryptr <- tiledb:::libtiledb_query(ctx@ptr, arrptr, "WRITE")
qryptr <- tiledb:::libtiledb_query_set_subarray(qryptr, subarr)
qryptr <- tiledb:::libtiledb_query_set_layout(qryptr, "ROW_MAJOR")
qryptr <- tiledb:::libtiledb_query_set_buffer(qryptr, "a", vec)
qryptr <- tiledb:::libtiledb_query_submit(qryptr)
res <- tiledb:::libtiledb_array_close(arrptr)
# TODO Higher-level R support
Java
// ... create context ctx
// Open encrypted array for writing
String key = "0123456789abcdeF0123456789abcdeF";
Array array(ctx, "<array-uri>", TILEDB_WRITE, TILEDB_AES_256_GCM, key..getBytes(StandardCharsets.UTF_8));
Go
// ... create context ctx
// The 256-bit encryption key, stored as a string for convenience.
var encryption_key = "0123456789abcdeF0123456789abcdeF"
// Open encrypted array for writing
array, _ := tiledb.NewArray(ctx, "<array-uri>")
array.CreateWithKey(schema, tiledb.TILEDB_AES_256_GCM, encryption_key)