Angular обещание DataError - PullRequest
       54

Angular обещание DataError

0 голосов
/ 21 февраля 2020

У меня есть служба в 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));
  }
  ....   

, и я использовал метод 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')
  );   

У меня возникает эта ошибка, когда receive [server publicKey]:

Ошибка: «Uncaught (в обещании): DataError: Данные, предоставленные для операции, не соответствуют требованиям»

Не могу понять Как решить эту проблему.
Какая часть моего кода имеет проблемы?

ОБНОВЛЕНИЕ:
Отладка браузера: enter image description here

...