Guide for adding Chinese characters with digital signature in your jsrsasign.js code

I am currently working on integrating with third-party organizations that require a digital signature to be added to the data in the request header.

After some research, I decided to utilize the jsrsasign.js library for handling the digital signature process. However, I have been encountering issues with getting the correct result.

Here is the code snippet I have been using:

import { RSAKey, KEYUTIL, KJUR, hex2b64 } from 'jsrsasign'
export function createSignature (url) {
  // Create RSAKey object
  var rsa = new RSAKey()
  let privateKey = '-----BEGIN PRIVATE KEY-----x-----END PRIVATE KEY-----'
  
  // Convert key to proper format
  rsa = KEYUTIL.getKey(privateKey)
  
  // Create Signature object and set encryption algorithm
  var sig = new KJUR.crypto.Signature({'alg': 'SHA256withRSA'})
  
  // Initialize signature
  sig.init(rsa)
  
  console.log('***url***', url)
  
  // Update string to be encrypted
  sig.updateString(url)
  
  // Generate ciphertext
  var signature = hex2b64(sig.sign())
  console.log('**signature**', signature)
  
  return signature
}

Answer №1

As a maintainer of jsrsasign, I can assure you that it will function properly if your code or page is in UTF-8, including Chinese, Cyrillic, or Japanese characters.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The following authentication error occurred: JWEDecryptionFailed - the decryption process has encountered a failure

[...nextauth]/route.js file import { User } from "@/lib/models"; import { connectToDb } from "@/lib/utils"; import NextAuth from "next-auth"; import GitHubProvider from "next-auth/providers/github"; export const aut ...

Employ jQuery to display a text box with a sliding motion upon hovering the mouse cursor over a specific area

Beginner inquiry about jQuery. Imagine I have a label on my webpage and I am looking to create a sliding effect for an input box when hovering over the label. Can anyone offer tips on utilizing jQuery to make this happen? ...

Retrieve information from an express server using the fetch API

I am attempting to use the alert function to display a variable string in Express's .get() method and then send it using res. I want the alert to show "I am working fetch". This is my server.js var express = require('express'); var app = e ...

Ways to send a variable to a component through history.replace

Is there a way to retrieve the match.chatroomId in a functional component? I am currently using history.replace to navigate to this component. Here is the code snippet: onClick = {() => history.replace(`/chat/${match.chatroomId}`)} ...

Tips for executing a JavaScript function when items in a checkbox list are selected

Here is an example of HTML code: <asp:CheckBoxList ID="CheckBoxList1" runat="server"> <asp:ListItem>C++</asp:ListItem> <asp:ListItem>ASP.Net</asp:ListItem> <asp:ListItem>Javascript</asp:ListItem> ...

Troubleshooting a "Cannot GET" error while using Vue.js with a REST API

I am currently working on a project with Vue.js and I am running it locally through npm (Node). As a newcomer to Rest APIs, I followed an online tutorial to create a simple REST API. The file is named employees.php <?php // Establish database connect ...

When attempting to create text with Three.js using the TextBufferGeometry method, an error arises indicating that the property yMax is unreadable due

While trying to add text to a three.js scene, I encountered the error message "Uncaught TypeError: Cannot read property 'yMax' of undefined". let loader = new THREE.FontLoader(); let font = loader.parse( jsonFont ); let geometry = new THRE ...

Efficiently process and handle the responses from Promise.all for every API call, then save the retrieved data

Currently, I am passing three API calls to Promise.all. Each API call requires a separate error handler and data storage in its own corresponding object. If I pass test4 to Promise.all, how can I automatically generate its own error and store the data in ...

Is there a way to retrieve values from a different menu without the need to refresh the page?

Whenever a radio button is clicked on a form, a popup menu is displayed. The popup menu is implemented using the Bootstrap module. However, there is an issue where selecting an option from the popup menu causes the form to reset, resulting in the loss of ...

In the Sandbox, element.firstChild functions properly, but it does not work in the IDE

Encountered an issue that has me puzzled. To give you some context, I attempted to create a native draggable slider using React and positioned it in the center of the screen, specifically within my Codesandbox file. The code snippet I utilized is as follow ...

Using Three.js to Manipulate Objects through Their Names

Is there a way to access multiple meshes with the same name? var mesh1 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0xffffff })); mesh1.name = "meshes"; scene.add( mesh1); var mesh2 = new THREE.Mesh( geometry, new THREE.MeshBasicMate ...

Enhance your user interface by incorporating badges into specific elements using Bootstrap version 5.2

I am currently using the most recent version of Bootstrap v5.2 and Vue 3 (for learning purposes). While searching on Stackoverflow, I came across a similar question, but it was related to an older Bootstrap version. In my project, I have a select element ...

NodeJS module loading issue

Currently, I am attempting to utilize the resemblejs library () in order to compare two images. Despite creating a directory and adding resemblejs as a dependency, when running nodejs test.js, an error occurs: var api = resemble(fileData).onComplete(funct ...

Can someone help me locate the file using the inspect element feature?

Today, I encountered a small issue on my website that I wanted to fix. Although I was able to make the necessary changes using Inspect Element, I couldn't locate the file where it needed to be changed. The website in question is gesher-jds.org/giving. ...

The precision of the css function in jQuery

Possible Duplicate: jQuery and setting margin using jQuery In the HTML snippet below, I have set margins for a paragraph element to center it: <p style="margin-left:auto; margin-right:auto; width:200px;">Hello</p> After that, I attempted ...

An unexpected key was found in the create store function in React Redux

Encountering the issue An unexpected key "characters" was found in the initialState argument passed to createStore. Expected keys are: "marvelReducer", "routing". Any unexpected keys will be disregarded. rootReducer : import { combineReducers } from &a ...

Press anywhere on the screen to conceal the AngularJS element

Attempting to create a toggle effect using 2 ng-click functions. One is bound to a button, the other to the body tag. The goal is for my content to show when the button is clicked and hide when anywhere on the body is clicked. However, it seems that Angul ...

Tips for resolving issues with dynamically displaying state information based on a selected country

I'm currently working on a project that requires me to dynamically fetch the states of a specific country when a user selects the country of birth for their family members. To do this, I am utilizing AJAX. Due to limitations, I can only include detai ...

I'm struggling to understand the reasoning behind the 'undefined' error occurring in the Google Maps distance service

Currently facing a puzzling issue with an 'undefined' exception. Developing a tool to track distance traveled between two locations, leveraging Google Maps distance matrix. Upon selecting a vehicle, entering an origin and destination, and clickin ...

Is there a way to make res.render in node.js/express/mongo wait until the database search is finished before loading?

Having some difficulty with loading a table properly on my page because the information is not being passed to the ejs template before the page loads. I'm fairly new at this and could use some assistance! Just a heads up, owneditems consists of an ar ...