为什么JS“加密”模块给出typeError? background: 我正在使用加密模块来消化哈希的字符串,并将结果缓冲区转换为字符串。结果功能返回承诺

问题描述 投票:0回答:1
模块将hashing的字符串转换为字符串。结果函数返回A

digest

这是我的代码:

Promise<String>
该代码居住在我的
export default async function hashPassword(unHashedPassword) { return crypto.subtle.digest('SHA-256', unHashedPassword) .then((hash) => _arrayBufferToBase64(hash)) } function _arrayBufferToBase64( buffer ) { let binary = ''; const bytes = new Uint8Array( buffer ); const len = bytes.byteLength; for (let i = 0; i < len; i++) { binary += String.fromCharCode( bytes[ i ] ); } return btoa( binary ); }
app的文件夹中的一个名为
hasher.js

文件中的文件中。 然后,该函数被用来放置用户输入形式的各种数据。我这样用它:

libs
,但是,当代码的这一部分运行时,我会收到以下错误:

NextJS

我试图修复它的方法:

首先,我认为也许图书馆丢失了。我可以确认这是不正确的,因为它是由IDE索引的。

next,我查找了这个,发现
const licenseKey = formData.get('licenseKey')
const hashedPasswordPromise = hashPassword(licenseKey)
hashedPasswordPromise.then(hashedPassword => {
    console.log("Hashed License:", hashedPassword)
})
模块只能在一个

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'digest')

中起作用(当时我正在使用

crypto

)。因此,我将使用SSL设置
SecureContext

以将请求反向代理到

httpnginx

。证书被添加到

next

且值得信赖(浏览器上没有警告,都安全)。但是,这个问题仍然存在。

next,我考虑了启动

https
启动
keychain
启动。我唯一能找到的结果是我所做的
next
https
或使用
nginx
,这仅在
--experimental-https
而不是生产中可用,这是不好的。 我很难过。关于如何解决此问题的任何建议?
    

指出

dev
实际上是
subtle
i用此代码替换了我的功能,现在可以工作(并且更好,因为它只是返回a
undefined
而不是a
string

Promise<String>

javascript next.js https hash cryptography
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.