Is there a way to achieve RSA key pair encryption/decryption in Ruby and JavaScript?

I have been experimenting with encrypting data in Ruby using OpenSSL and decrypting it in JavaScript using the JavaScript Forge library.

Although the method of distributing keys is functional for research purposes, I am encountering an issue where encrypting the same string with the same key in both languages results in different outputs, preventing successful encoding/decoding between the two.

Is there a recommended approach to resolve this discrepancy?

Additionally, transferring binary data strings from Ruby to JavaScript without encountering incompatible type errors necessitates conversion methods such as converting encrypted data to hexadecimal. However, manipulating this information in the forge library has proven to be challenging.

Answer №1

After some trial and error, I managed to find the solution to my initial issue.

It turns out that I simply wasn't executing the correct steps.

For those who may encounter a similar situation in the future, if you're utilizing the ruby openssl RSA encryption and need to transfer it to javascript, I suggest utilizing the https://github.com/digitalbazaar/forge library on the JS side.

Furthermore, make sure to convert encrypted strings to hex by using the .unpack('H*') method.

The Forge PKI library offers a convenient .hexToBytes() function which can then be utilized with the forge .decrypt method to retrieve your original data.

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

Is there a way to track and detect alterations to an element using JavaScript or jQuery

Can I detect the addition of a specific CSS class to an element without having to create a new event? ...

Adding custom fields to the user model in MongoDB using Next Auth during login is not possible

When a user logs in via next auth, I am looking to include custom fields to the default user model. I followed the instructions provided in the official documentation at https://next-auth.js.org/tutorials/typeorm-custom-models. Here is the code snippet: ...

Looking for assistance with a simple Javascript program

My program needs to have a for loop and utilize existing input functions (name and number). Additionally, I need to calculate totals. Users should be able to CANCEL and proceed to doc.write where they can enter their name and number. Furthermore, users s ...

Injecting Vue components and dynamically rendering them in real-time

Presently, I am in the process of developing a third-party application where Vue.js is being utilized to render components. In this setup, the third-party app loads the component dynamically after the Vue app has been initialized and mounted. Due to this ...

JS showcase of object literals and their corresponding properties

Just starting out with Javascript and eager to learn about arrays of objects. I'm currently exploring how to display an object along with its properties. Here's an example showcasing the colors of different fruits: var fruitColor = {'apples ...

Having trouble with jQuery functioning on mobile devices?

I'm experiencing an issue where this code works perfectly on my desktop, but not on my mobile device. I've tried using different browsers on my mobile, but the code still doesn't function. Any assistance would be greatly appreciated. var li ...

ng-display does not display content when the condition switches to true

I am facing an issue with displaying an image and a YouTube video in my HTML. My goal is to show the image when the video is not playing, and switch to displaying the video when it starts playing. Upon loading the page, only the image is shown, which is ...

Issue with AJAX loading functionality not functioning properly in Internet Explorer

For a project, I have a portfolio that I need to create. The front page consists of a div with a loader which determines the screen size upon landing and selects the content to be pulled in using ajax. The reason for this approach is due to the simplicity ...

Is it possible for CKEditor Plugin to extend allowedContent to elements further down the hierarchy, or is there a way to deactivate the MagicLine for specific elements?

I am in the process of developing a Drupal module that is inspired by the CKEditor Accordion Module, but with a twist of using Bootstrap 4 instead. The generated HTML markup by this module looks something like this: <section class="accordion" id="Acco ...

"Enhance your gaming experience with Three JS special effects

I'm in the process of creating a multiplayer web game using Three JS. So far, I have successfully implemented the game logic on both client and server sides, mesh imports, animations, skill bars, health bars, and the ability for players to engage in c ...

The presence of a default value within an Angular ControlValueAccessor triggers the dirty state due to

My task is to create dynamic Input components for a template driven form using a directive. The default value of the Input component should be set by the component itself. However, I encountered an issue where setting a default value automatically marks t ...

Angular component equipped with knowledge of event emitter output

I have a custom button component: @Component({ selector: "custom-submit-button" template: ` <button (click)="submitClick.emit()" [disabled]="isDisabled"> <ng-content></ng-content> </butto ...

Update the appearance of Morris Donut following an AJAX request

Currently, I am implementing Morris Donut for a dashboard project and using AJAX to fetch data with two date ranges as parameters. However, I am encountering an issue where entering new date ranges results in rendering a new Donut Chart on top of the exist ...

Appears as though time is slipping away during date conversions

I seem to be experiencing a strange issue where I lose a day when transitioning between MySQL and my JavaScript code, and I can't seem to figure out why. When I insert a date into the database (for example, 10/14/12), it appears as 10/13/12 in the dat ...

Conducting Ajax polling simultaneously with another ongoing Ajax operation

I have a single form on my webpage. After submitting the form, an Ajax call is made to the server, which uses C# asp.net on the backend. Once the server controller processes the request and saves the current state in the Session, the Ajax call takes about ...

Having trouble organizing sequellize results according to fields in the joined table

I am currently working with three sequelize models as outlined below: tags: id tag_name product_tags: id tag_id --> Reference Key 'id' from tags product_id --> Reference Key 'id' from products tag_score products: id name My ob ...

Sending an array to another file upon button click event in a React application

Hey everyone, I'm currently getting started with React. I have this interesting situation where I need to handle an array of IDs that are obtained from selected checkboxes. My goal is to pass this array to another file called Employee.js when a button ...

The array within the JSON object holds vital information [Typescript]

I have some data stored in an Excel file that I want to import into my database. The first step was exporting the file as a CSV and then parsing it into a JSON object. fname,lname,phone Terry,Doe,[123456789] Jane,Doe,[123456788, 123456787] Upon convertin ...

Error message: The variable datepicker_instActive is not defined within Jquery-ui Datepicker

Having trouble with a Rails + Angular app where I've implemented the jquery-ui datepicker. The console is showing an error that says: TypeError: datepicker_instActive is undefined if(!$.datepicker._isDisabledDatepicker( datepicker_instActive.inline? ...

utilizing django with sizeable jquery datagrids causes performance issues

I am currently facing an issue with rendering a large dataset (20k rows) in a jQuery datatable within a Django project. The rendering process is very slow, and I am looking for alternative approaches to speed it up. One suggestion I came across is using de ...