D0n9X1n / hexo-blog-encrypt

Yet, just another hexo plugin for security.
https://www.npmjs.com/package/hexo-blog-encrypt
MIT License
1.01k stars 103 forks source link

希望适配移动端,添加输入密码后确定的button #222

Open paradoxsugar opened 4 months ago

paradoxsugar commented 4 months ago

Issue

移动端输入法经常没有回车键,回车键处由“下个”代替,点击后若开启评论则跳转到评论区而无法输入密码

Expected Behavior

添加类似于“encrypt again”的button,实现代替回车功能; 虽然#200存在修改方案,但是依然觉得有一个button更好,希望纳入更新计划

tuneq commented 3 months ago

+1

xsstomy commented 1 month ago

hbe.js 里面加了下面的代码,凑合使用

image


 let timeout

    function delay(ms) {
      return new Promise((resolve) => {
        timeout = setTimeout(resolve, ms);
      });
    }

    passwordElement.addEventListener("input", async () => {
      clearTimeout(timeout);

      await delay(1000);

      const password = document.getElementById("hbePass").value;
      const keyMaterial = await getKeyMaterial(password);
      const hmacKey = await getHmacKey(keyMaterial);
      const decryptKey = await getDecryptKey(keyMaterial);
      const iv = await getIv(keyMaterial);

      decrypt(decryptKey, iv, hmacKey).then((result) => {
        console.log(`Decrypt result: ${result}`);
        if (result) {
          cryptoObj.subtle.exportKey("jwk", decryptKey).then((dk) => {
            cryptoObj.subtle.exportKey("jwk", hmacKey).then((hmk) => {
              const newStorageData = {
                dk: dk,
                iv: arrayBufferToHex(iv),
                hmk: hmk,
              };
              storage.setItem(storageName, JSON.stringify(newStorageData));
            });
          });
        }
      });
    });