Shows how to use field-encryption API to decrypt JSON values.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#define PRIx64 "I64x"
#else
#include <inttypes.h>
#endif
#include "openssl_symmetric_provider.h"
{
exit(EXIT_FAILURE);
}
static void op_callback(
lcb_INSTANCE *instance,
int cbtype,
const lcb_RESPBASE *rb)
{
if (rb->rc == LCB_SUCCESS) {
printf("VALUE: %.*s\n", (int)rg->nvalue, rg->value);
field.
alg =
"AES-256-HMAC-SHA256";
if (err != LCB_SUCCESS) {
die(instance, "Couldn't decrypt field 'message'", err);
}
die(instance, "Crypto provider returned success, but document is NULL", LCB_ERR_INVALID_ARGUMENT);
}
if (dcmd.
out[dcmd.
nout - 1] ==
'\n') {
}
printf(
"PLAIN: %.*s\n", (
int)dcmd.
nout, dcmd.
out);
printf("CAS: 0x%" PRIx64 "\n", rb->cas);
} else {
}
}
static void get_encrypted(
lcb_INSTANCE *instance,
const char *key)
{
lcb_CMDGET cmd = {};
printf("KEY: %s\n", key);
err = lcb_get3(instance, NULL, &cmd);
if (err != LCB_SUCCESS) {
die(instance, "Couldn't schedule get operation", err);
}
}
int main(int argc, char *argv[])
{
{
struct lcb_create_st create_options = {};
create_options.version = 3;
if (argc < 2) {
fprintf(stderr, "Usage: %s couchbase://host/bucket [ password [ username ] ]\n", argv[0]);
exit(EXIT_FAILURE);
}
create_options.v.v3.connstr = argv[1];
if (argc > 2) {
create_options.v.v3.passwd = argv[2];
}
if (argc > 3) {
create_options.v.v3.username = argv[3];
}
if (err != LCB_SUCCESS) {
die(NULL, "Couldn't create couchbase handle", err);
}
if (err != LCB_SUCCESS) {
die(instance, "Couldn't schedule connection", err);
}
if (err != LCB_SUCCESS) {
die(instance, "Couldn't bootstrap from cluster", err);
}
}
get_encrypted(instance, "secret-1");
printf("\n");
get_encrypted(instance, "secret-2");
printf("\n");
get_encrypted(instance, "secret-3");
printf("\n");
get_encrypted(instance, "secret-4");
printf("\n");
get_encrypted(instance, "secret-5");
return 0;
}