1

我正在使用加密 API 进行签名并将其发送到使用开放 SSL 验证签名的网络服务器。签名使用 Windows 加密 API 成功验证,但在服务器端使用开放 SSL 验证时出错。

错误:

ECDsa 签名不是有效的 DER 序列

签名功能:

  public async sign(data: Uint8Array): Promise<any> {
    if (!this.privateKey) {
        throw new Error('no private key available for signing');
    }
    return window.crypto.subtle.sign(
        this.getKeyParams(),
        this.privateKey,
        data,
    );
}

private getKeyParams(): EcdsaParams {
    return { name: 'ECDSA', hash: coseEllipticCurveNames[ECDSA.ellipticCurveKeys[this.algorithm]] };
}

private async toCOSE(key: CryptoKey): Promise<Map<number, any>> {
    const exportedKey = await window.crypto.subtle.exportKey('jwk', key);
    const attData = new Map();
    attData.set(1, 2); // EC2 key type
    attData.set(3, this.algorithm);
    attData.set(-1, ECDSA.ellipticCurveKeys[this.algorithm]);
    attData.set(-2, base64ToByteArray(exportedKey.x, true));
    attData.set(-3, base64ToByteArray(exportedKey.y, true));
    return attData;
}
4

0 回答 0