Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
paradoxsugar opened this issue Jul 19, 2024 · 6 comments
Open

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

paradoxsugar opened this issue Jul 19, 2024 · 6 comments

Comments

@paradoxsugar
Copy link

paradoxsugar commented Jul 19, 2024

Issue

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

Expected Behavior

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

@tuneq
Copy link

tuneq commented Jul 27, 2024

+1

@xsstomy
Copy link

xsstomy commented Sep 28, 2024

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));
            });
          });
        }
      });
    });

@FrWalkerCn
Copy link

修改插件对应文件:
image
image
image
即可:
image

@FrWalkerCn
Copy link

同时纠正一下此处代码的逻辑:
image

@wuqi9277
Copy link

wuqi9277 commented Jan 29, 2025

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

image


 let timeout;

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

    mainElement.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));
            });
          });
        }
      });
    });

修正一些小问题

@wuqi9277
Copy link

wuqi9277 commented Jan 29, 2025

再提供一个小的修补,在密码错误时会不断弹窗,增加一个判断,同时修补移动端支持(密码填写后会直接自动验证
node_modules\hexo-blog-encrypt\lib 目录下,替换 hbe.js 为我提供的,记得重命名哦

hbe.js.md

借鉴了 @xsstomy 的思路,希望 @D0n9X1n 提交至仓库

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants