Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

utils.js 877 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  1. var crypto = require('crypto');
  2. var algo = 'aes-256-ctr';
  3. var password = 'itsasecret!';
  4. function serializeAddress(address) {
  5. return JSON.stringify(address);
  6. }
  7. function deserializeAddress(json) {
  8. return JSON.parse(json);
  9. }
  10. function encrypt(input) {
  11. var cipher = crypto.createCipher(algo, password);
  12. var encrypted = cipher.update(input, 'utf8', 'hex');
  13. encrypted += cipher.final('hex');
  14. return encrypted;
  15. }
  16. function descrypt(cryptedInput) {
  17. var decipher = crypto.createDecipher(algo, password);
  18. var decryted = decipher.update(cryptedInput, 'hex', 'utf8');
  19. decryted += decipher.final('utf8');
  20. return decryted;
  21. }
  22. module.exports = {
  23. serializeAddress: function (address) {
  24. return encrypt(serializeAddress(address));
  25. },
  26. deserializeAddress: function (input) {
  27. return deserializeAddress(descrypt(input));
  28. }
  29. };
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...