NestJS - 尝试复制 Symphony 2 PHP 加密程序 FOSUserBundle

问题描述 投票:0回答:0

我正在尝试将 symphony 2 密码加密的过程从 fosuserbundle 迁移到 NestJS。考虑到here这个问题,我做了一些小的修改,创建了以下程序:

      const salted = pass + '{' + user.salt + '}';
      let hash = crypto.createHash('sha512').update(salted, 'utf-8');
      for (let i = 1; i < 5000; i++) {
        hash = crypto
          .createHash('sha512')
          .update(hash.digest().toString('binary') + salted);
      }
      const finalString = hash.digest('base64');

但是,我不太确定 digest().toString('binary')digest('binary') 具有相同的预期行为。后者已被弃用,因为它似乎来自加密文档和尝试编译时抛出异常TS2345:“二进制”类型的参数不可分配给“BinaryToTextEncoding”类型的参数。.

这里 digest().toString('binary') 的用法正确吗?

我尝试将 ts-ignore 用于 digest().toString('binary'),但我不太了解它的工作原理。

node.js hash cryptography nestjs fosuserbundle
© www.soinside.com 2019 - 2024. All rights reserved.