|
Post by salvatore on Jan 8, 2021 15:51:18 GMT
Hy Andrea,
Ti auguri un felice anno nuovo :-)
I am playing with Secretely, how to store the encrypted value in a variable, and pass it to decrypt ?
Grazie
Salvatore
|
|
|
Post by webreflection on Jan 8, 2021 16:07:08 GMT
Hello there, e felice anno nuovo 👋 Isn't the very first example good enough? github.com/WebReflection/secretly#usageThe only thing you need to be aware of, is that if you don't pass the third argument you can't decrypt anything next session. import Secretly from 'secretly/web'; // or secretly in node
// uses default PATH and make it *not* random const secret = new Secretly('P4ssw0rd!', Secretly.PATH, false);
secret.encrypt(anyString).then(encrypted => { // do the thing with encrypted value });
// or secretly.descrypt(encrypted).then(descrypted => { console.log(descrypted); });
Does this help?
|
|
|
Post by salvatore on Jan 8, 2021 17:26:09 GMT
In fact, I have stored the encrypted value in localstorage. anf when I try to retore it with
let code = localStorage.getItem("code") pvt.decrypt(code).then(c => console.log(c))
I get the following error :
index.html:1 Uncaught (in promise) DOMException
|
|
|
Post by webreflection on Jan 8, 2021 17:40:18 GMT
does this CodePen help? codepen.io/WebReflection/pen/YzGjVbr?editors=1000check the HTML panel import Secretly from '//unpkg.com/secretly/esm/web.js?module';
const secret = new Secretly('P4ssw0rd!', Secretly.PATH, false);
const value = localStorage.getItem('secretly');
if (value) showContent(value); else { secret.encrypt(`Value: ${Math.random()}`).then(enc => { localStorage.setItem('secretly', enc); showContent(enc); }); }
function showContent(value) { secret.decrypt(value).then(dec => { document.body.textContent = dec; }); }
|
|
|
Post by salvatore on Jan 9, 2021 14:33:10 GMT
Perfetto :-)
Grazie mille
|
|