Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从文件导入JWK签名并验证信息Web加密API_Javascript_Cryptography_Sign_Verify_Jwk - Fatal编程技术网

Javascript 从文件导入JWK签名并验证信息Web加密API

Javascript 从文件导入JWK签名并验证信息Web加密API,javascript,cryptography,sign,verify,jwk,Javascript,Cryptography,Sign,Verify,Jwk,无法使用Web加密API和RSASSA-PKCS1-v1_5算法密钥验证签名 将postgreSQL中使用生成的签名另存为字符串: 我尝试使用从postgreSQL获得的签名进行验证: UTIL: *字符串->数组缓冲函数: private str2ab(str) { var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char var bufView = new Uint16Array(buf);

无法使用Web加密API和RSASSA-PKCS1-v1_5算法密钥验证签名

  • 将postgreSQL中使用生成的签名另存为字符串:
  • 我尝试使用从postgreSQL获得的签名进行验证:
  • UTIL: *字符串->数组缓冲函数:

    private str2ab(str) {
        var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
        var bufView = new Uint16Array(buf);
        for (var i = 0, strLen = str.length; i < strLen; i++) {
          bufView[i] = str.charCodeAt(i);
        }
        return buf;
      }
    
    问题是,即使我使用了正确的密钥对进行签名和验证,我也总是从verify函数得到“false”作为响应

    window.crypto.subtle
              .verify(
                "RSASSA-PKCS1-v1_5",
                key,
                this.str2ab(_signature), //from pSQL
                this.str2ab(_hash) //from pSQL
              )
              .then(isVerified => {
                console.log(isVerified);
              });
    
    private str2ab(str) {
        var buf = new ArrayBuffer(str.length * 2); // 2 bytes for each char
        var bufView = new Uint16Array(buf);
        for (var i = 0, strLen = str.length; i < strLen; i++) {
          bufView[i] = str.charCodeAt(i);
        }
        return buf;
      }
    
    private ab2hex(buffer) {
        // buffer is an ArrayBuffer
        return Array.prototype.map
          .call(new Uint8Array(buffer), x => ("00" + x.toString(16)).slice(-2))
          .join("");
      }