javascript - 角度承诺数据错误
问题描述
我在 Angular 9 项目中使用以下方法提供服务:
....
private importECDHPublicKey(publicKey) {
const algorithm = {
name: 'ECDH',
namedCurve: 'P-256',
};
const pk = new TextEncoder().encode(atob(publicKey));
return crypto.subtle.importKey('raw', pk, algorithm, false, ['deriveKey', 'deriveBits']);
}
private driveECDHPublicKey(publicKey) {
const algorithm = {
name: 'ECDH',
public: publicKey,
};
const derivedKeyType = {
name: 'AES-CBC',
length: 256,
};
return crypto.subtle.deriveKey(algorithm, this.ecdhPrivateKey, derivedKeyType, false, ['encrypt', 'decrypt']);
}
public generateSharedSecretKey(publicKey) {
this.sharedSecret = this.importECDHPublicKey(publicKey)
.then(e => this.driveECDHPublicKey(e))
.then(e => this.deriveECDHSecretKey(this.ecdhPrivateKey, e));
}
....
我在我的 websocket 连接中使用了 generateSharedSecretKey 方法:
this.ws
.pipe(retryWhen(e => e.pipe(delay(1000))))
.pipe(e => e.pipe(delay(1000)))
.subscribe(
msg => myService.generateSharedSecretKey(msg),
err => console.log(err),
() => console.log('Completed')
);
收到 [server publicKey] 时出现此错误:
错误错误:“未捕获(承诺):DataError:提供给操作的数据不符合要求”
我无法理解如何解决这个问题。
我的代码的哪一部分有问题?
解决方案
推荐阅读
- android - 从 mainActivity 开始时停止另一个类的进度条
- php - 使用 AWS S3 createMultipartUpload (AWS PHP SDK v3) 上传进度统计信息
- redis - Redis:按成员排序的排序集¿?
- sql - SQL中的Excel索引匹配 - 从矩阵中查找值
- reporting-services - SSRS:书签/DocumentMap 功能在部署的报告中非常慢
- reactjs - 我的代码还可以我仍然收到此错误“预期分配或函数调用,而是看到一个表达式”
- python - jupyter ModuleNotFoundError:没有名为 Tensorflow 或 keras 的模块
- bash - 如何解析 bash 脚本给出的错误?
- visual-studio-code - Ctrl + tab 在 vscode 中突然停止工作
- c# - MessageBox.Show 显示太快