A
A
Adel Khalitov2019-06-12 22:58:58
JavaScript
Adel Khalitov, 2019-06-12 22:58:58

How to encrypt to a string using bcrypt?

There is a frontend on the angular, there is a backend on the node.
I need to encrypt a json object using bcrypt, for further saving it in local storage, then when I need it, I need to decrypt it on the front.
How can I use bcrypt to encrypt data into a string that can then be decrypted with the secret?
And where do I keep secrets safely?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Karo, 2019-06-13
@Zraza

Bcrypt is not suitable, encryption is one-way, i.e. the original data from the encrypted cannot be obtained.
There is a library with many popular encryption algorithms, you can use, for example, AES
https://github.com/brix/crypto-js
It also seems to work under the browser (not tested)
Where to store is a matter of application logic. If it is assumed that user data is stored on the server in encrypted form, then it is better not to store secrets anywhere, but to ask the user at the time of decryption on the client.

G
grinat, 2019-06-13
@grinat

Here is a reversible one https://www.npmjs.com/package/mcrypt but it won't work on the front unless you rebuild under wasm. And there is no point in keeping it at the front, because if the decryption key is sent to the front, then anyone can decrypt it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question