-1

const clientEncryption = new ClientEncryption(unencryptedClient, { kmsProviders, keyVaultNamespace, });

// genrate encyption key
const dataKeyId = await clientEncryption.createDataKey("local").then(() =\> {
  console.log("Encyption key genrated");
});

const schemaMap = {
  \[\`${dbName}.${collName}\`\]: {
    properties: {
      sensitiveField: {
        encrypt: {
          keyId: \[dataKeyId\],
          bsonType: "string",
          algorithm: "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
        },
      },
    },
  },
};

const encryptedClient = new MongoClient(URL, {
  useUnifiedTopology: true,
  autoEncryption: {
    keyVaultNamespace,
    kmsProviders,
    schemaMap,
  },
});

try {
  await encryptedClient.connect();
  const db = encryptedClient.db(dbName);
  const collection = db.collection(collName);

  `const` doc = {
    medicalRecords: "my-sensitive-data",
    sensitiveField: "hsbdb-jd256b",
    bloodType: "O+",
    insurance: "hgvdw35w6-7643",
  };


  const result = await collection.insertOne(doc);
  // const result = await collection.findOne({ bloodType: "O+" });
  // console.log("result: ", result);
  if (result) console.log("data entered successfully");
} catch (error) {
  console.log("Error:", error);
}

i try to encrypt databse using mongodb-client-encryption

purpose is Client-Side Field Level Encryption

dododo
  • 3,872
  • 1
  • 14
  • 37

1 Answers1

0

27020 is a default port for mongocryptd binary. See description in #2 here. However, I would recommend using shared library instead mongocryptd. See my answer here in particular part about cryptSharedLibPath

dododo
  • 3,872
  • 1
  • 14
  • 37