Files: 6df421c40b28e10fe7138c1519f7c78ebb52f470 / tmpl / docs / basics / encryption.html.js
1388 bytesRaw
1 | var page = require('../../page.part') |
2 | var com = require('../../com.part') |
3 | |
4 | module.exports = () => page({ |
5 | section: 'docs', |
6 | tab: 'docs-basics', |
7 | path :'/docs/basics/encryption.html', |
8 | content: ` |
9 | <h2>Publish an Encrypted Message</h2> |
10 | ${ com.code({ js: jsSnippet1 }) } |
11 | <h2>Decrypt a Message</h2> |
12 | ${ com.code({ js: jsSnippet2 })} |
13 | <h2>Is a message encrypted?</h2> |
14 | ${ com.code({ js: jsSnippet3 })} |
15 | <p class="next"><a href="/docs/social/follow-users.html">Follow users</a></p> |
16 | <ul class="see-also"> |
17 | <li><a href="/advanced/private-box.html">Private Box</a></li> |
18 | <li><a href="/advanced/linking-messages.html">Linking messages</a></li> |
19 | </ul> |
20 | ` |
21 | }) |
22 | |
23 | var jsSnippet1 = ` |
24 | sbot.private.publish( |
25 | // message: |
26 | { |
27 | type: 'post', |
28 | text: 'Hello, friend!' |
29 | }, |
30 | // recipient PKs: |
31 | [ |
32 | '@hxGxqPrplLjRG2vtj...wQpS730nNwE=.ed25519', |
33 | '@EMovhfIrFk4NihAKn...8pTxJNgvCCY=.ed25519' |
34 | ], |
35 | // cb: |
36 | function (err, privateMsg) { |
37 | // privateMsg.value.content is |
38 | // an encrypted string |
39 | } |
40 | ) |
41 | ` |
42 | |
43 | var jsSnippet2 = ` |
44 | sbot.private.unbox( |
45 | privateMsg.value.content, |
46 | function (err, content) { |
47 | // 'content' is now an object |
48 | // (if you were a recipient) |
49 | } |
50 | ) |
51 | ` |
52 | |
53 | var jsSnippet3 = ` |
54 | function isPlaintext (msg) { |
55 | return (typeof msg.value.content == 'object') |
56 | } |
57 | function isEncrypted (msg) { |
58 | return (typeof msg.value.content == 'string') |
59 | } |
60 | ` |
Built with git-ssb-web