MCPcopy
hub / github.com/bitwiseshiftleft/sjcl / doEncrypt

Function doEncrypt

demo/example.js:53–90  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51}
52/* Encrypt a message */
53function doEncrypt() {
54 var v = form.get(), iv = v.iv, password = v.password, key = v.key, adata = v.adata, aes, plaintext=v.plaintext, rp = {}, ct, p;
55
56 if (plaintext === '' && v.ciphertext.length) { return; }
57 if (key.length == 0 && password.length == 0) {
58 error("need a password or key!");
59 return;
60 }
61
62 p = { adata:v.adata,
63 iter:v.iter,
64 mode:v.mode,
65 ts:parseInt(v.tag),
66 ks:parseInt(v.keysize) };
67 if (!v.freshiv || !usedIvs[v.iv]) { p.iv = v.iv; }
68 if (!v.freshsalt || !usedSalts[v.salt]) { p.salt = v.salt; }
69 ct = sjcl.encrypt(password || key, plaintext, p, rp).replace(/,/g,",\n");
70
71 v.iv = rp.iv;
72 usedIvs[rp.iv] = 1;
73 if (rp.salt) {
74 v.salt = rp.salt;
75 usedSalts[rp.salt] = 1;
76 }
77 v.key = rp.key;
78
79 if (v.json) {
80 v.ciphertext = ct;
81 v.adata = '';
82 } else {
83 v.ciphertext = ct.match(/"ct":"([^"]*)"/)[1]; //"
84 }
85
86 v.plaintext = '';
87
88 form.set(v);
89 form.ciphertext.el.select();
90}
91
92/* Decrypt a message */
93function doDecrypt() {

Callers

nothing calls this directly

Calls 1

errorFunction · 0.85

Tested by

no test coverage detected