How to encrypt pouchdb database

Background:

I am trying to encrypt a pouchdb database using the crypto-pouch library. I looked at the example shown at https://github.com/calvinmetcalf/crypto-pouch But for me this does nothing.

My code is:

<!DOCTYPE html>
<html ng-app="pouchdbApp">
 <head>
   <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
   <script src="pouchdbDemo.js"></script>
   <script src="http://cdn.jsdelivr.net/pouchdb/5.2.1/pouchdb.min.js"></script>
   <!-- <script src="crypto-pouch-master/bundle.js"></script> -->
   <script src="http://wzrd.in/standalone/crypto-pouch"></script>

   <script>
       var db = new PouchDB('kittens2');

       var password = "mypassword";

      db.crypto(password).then(function (publicKey) {
            console.log("publicKey");
   	    console.log(publicKey);
       });
   
       /* db.removeCrypto();  */

       var doc = {
		  "_id": "mittens",
		  "name": "Mittens",
		  "occupation": "kitten",
		  "age": 3,
		  "hobbies": [
		    "playing with balls of yarn",
		    "chasing laser pointers",
		    "lookin' hella cute"
 		   ]
		};
      
      db.put(doc);

      db.get('mittens').then(function (doc) {
         console.log(doc);
      });

   </script>

 </head>
 <body>

 </body>

</html>
Run code

But my code does not see any encryption of the entered data, or I do not see any public key.

Any clue how I should use the crypto-pouch library with pouchdb.

+4
source share
1 answer

: 1.x crypto-, (3.x), db.crypto(password) ,

db.crypto(password)
// <-- encryption set up

db.crypto(password);
db.put({_id: 'foo', bar: 'baz'}).then(function () {
    return db.get('foo');
}).then(function (doc) {
    console.log('decrypted', doc);
    return db.removeCrypto();
}).then(function () {
    return db.get('foo');
}).then(function (doc) {
    console.log('encrypted', doc);
})

(- v1.x):

( ), db.crypto, ,

db.crypto(password).then(function () {
   // <-- encryption set up
})

, , , , ,

db.removeCrypto();

, , -

db.crypto(password).then(function () {
   return db.put({_id: 'foo', bar: 'baz'});
}).then(function () {
    return db.get('foo');
}).then(function (doc) {
    console.log('decrypted', doc);
    return db.removeCrypto();
}).then(function () {
    return db.get('foo');
}).then(function (doc) {
    console.log('encrypted', doc);
})
+3

All Articles