js-nacl | Javascript High-level API | Cryptography library
kandi X-RAY | js-nacl Summary
kandi X-RAY | js-nacl Summary
Pure-Javascript High-level API to Emscripten-compiled libsodium routines.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of js-nacl
js-nacl Key Features
js-nacl Examples and Code Snippets
Community Discussions
Trending Discussions on js-nacl
QUESTION
I managed to find a Libsodium js library (JS-NaCl) for front end encryption and has setup my PHP backend for Libsodium encrypt/decrypt also. When I encrypt a JSON object like below
...ANSWER
Answered 2019-Dec-27 at 10:26The code needs some changes. On the JavaScript side (frontend):
The JavaScript object must be converted into a string.
Besides the data, nonce and key must also be encoded using Utf8. Although the key could also be hexadecimal encoded to a 16 bytes key, in this context it must be Utf8 encoded to a 32 bytes key, because
sodium.crypto_secretbox
expects a 32 bytes key. The expected nonce must be 24 bytes in size.Now the data can be encrypted.
sodium.crypto_secretbox
returns the data asUint8Array
, which must therefore be encoded for transfer into a suitable format, e.g. hexadecimal.
The corresponding code is:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install js-nacl
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page