首页 > 解决方案 > 角度承诺数据错误

问题描述

我在 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:提供给操作的数据不符合要求”

我无法理解如何解决这个问题。
我的代码的哪一部分有问题?

更新:
浏览器调试: 在此处输入图像描述

标签: javascriptangulartypescriptpromiseangular-promise

解决方案


推荐阅读