1

I'm searching for solution of encrypting my javascript object with some data (e.g. { data: [{...}, {...}] } ) into string and then be able to decrypt this back to the same object. These operations will be done on node.js server.

For now I'm stringifying object with JSON.stringify and then using base64 url encoding and decoding with https://www.npmjs.org/package/b64url. What I don't like here is that output string is even longer than stringified json.

I would like to have encrypted string with some restricted size. Is it possible? Maybe there are some npm packages ready for that purporse?

Thanks!

4
  • encrypted string with some restricted size - you cannot guarantee a size AND be able to decrypt it back, do you understand that? ) Commented Sep 12, 2014 at 6:29
  • @raina77ow I'm not an expert in encryption algorithms, but understand that it cannot be smaller but just thought there are some algorithms that won't increase the string length Commented Sep 12, 2014 at 6:42
  • 1
    Check rot then, or similar modules implementing rotation algorithms. Commented Sep 12, 2014 at 6:46
  • What kind of encryption are you looking for? The "major governments can't break it" flavor or the "kid next door can't look into my JSON data" pseudo cryptography? Rotational ciphers and base64 encoding are the latter kind. Commented Sep 12, 2014 at 10:01

1 Answer 1

1

I've wrote a NPM module that copes with this - object-encrypter https://github.com/voronianski/node-object-encrypter.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi and wow very helpful package! But there is one issue: how can someone use this in Angular 4? After installation: import * as ObjEncrypt from 'object-encrypter'; and then var engine = ObjEncrypt(key); console.log(engine.encrypt(user)); but I get this error: index.js:8 Uncaught TypeError: crypto.createHmac is not a function at hmac (index.js:8) at Object.../../../../object-encrypter/index.js (... Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.