Unusual Behavior: Node-forge AES Decryption Does Not Return the Expected Data. Issue in Angular/Typescript

Attempting to decipher a code to unveil the original information but encountering unexpected challenges. Seeking assistance:

Code:

general() {
    const foo = {
      pass: "Werwerw",
      username: "qqwewdxas"
    };
    var key = "d7rccozrm8q1iuvi";
    var iv = "ttmw0lipoht7kz18";
    console.log("Key", key);
    console.log("IV", iv);

    var cipher = forge.cipher.createCipher('AES-CBC', key);
    cipher.start({ iv: iv });
    cipher.update(forge.util.createBuffer(JSON.stringify(foo)));
    cipher.finish();
    var encrypted = cipher.output;
    // outputs encrypted hex
    console.log("Encrypted", encrypted.toHex());

    var decipher = forge.cipher.createDecipher('AES-CBC', key);
    decipher.start({ iv: iv });
    decipher.update(encrypted);
    var result = decipher.finish(); // check 'result' for true/false
    console.log("Decrypted", decipher.output.toHex());
  }

Response: Encrypted: 8e3cb8653b17fc0f5e50916d8d22ec666207babdb4b0b945ca06fde4cc31a6bc40222de1210d830f3d672f4001b69a30 Decrypted: 7b2270617373223a2257657277657277222c22757365726e616d65223a22717177657764786173227d

Answer №1

After countless days of hardship, I have at last discovered the solution. By passing the encrypted data as a buffer into the function, I was able to successfully decrypt it:

decipher.update(forge.util.createBuffer(encrypted)); #instead of decipher.update(encrypted);

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

Setting default values for class members in Typescript is important for ensuring consistent behavior and

My model is pretty straightforward: export class Profile extends ServerData { name: string; email: string; age: number; } Whenever I make a server call using Angular 4's $http, I consistently receive this response: { name: string; email: ...

What are the appropriate Typescript typings for React Components that have the ability to return a string or their child components directly?

What are the suitable types for a React Component that can also output a string or directly its children, in addition to a JSX.Element? For example: type PropsStringExample = Readonly<{ returnString: boolean; }>; type PropsChildrenExample = Readon ...

Accessing Child Properties in Parent Component using Typescript

New to the world of Typescript! Imagine having a component called TitleSubtitle that consists of both a Title and a Subtitle component. The Title component comes with props: interface TitleProps { text: string; } The Subtitle component also has props ...

Is there a way to retrieve the number of swipe up interactions from Instagram story insights using the graph API

Is there a way to retrieve the swipe up count displayed in Instagram insights? Since Facebook does not provide this data through their Graph API, how can I access it? I have already tried scraping without success and I am looking for a solution using eith ...

Following the npm update, encountering errors with webpack

Upgrading the npm package to version 8.2.0 has caused issues in my React application. Here is a screenshot of the problem: https://i.stack.imgur.com/noQIz.png These are the error messages I see in the console: [HMR] Waiting for update signal from WDS.. ...

Aframe failing to display image when using local path in Angular with AR.js

I am attempting to load an image from a local path within my Angular app component.html file. Below is the code snippet: <a-scene embedded arjs> <a-assets> <img id="test_img" src="/mnt/r/flipkart/proj/src/app ...

Generate a new Angular component by only creating the TypeScript file

As a newcomer to Angular, I recently purchased the Metronic theme. After installing all necessary components, including the latest version of angular CLI, I encountered an issue. Whenever I run the command ng generate component test, it only creates a test ...

What advantages does using an RxJS Subject have over handling multiple event listeners individually in terms of speed

After investigating a page's slow performance, I identified an angular directive as the root cause. The culprit was a piece of code that registered event listeners on the window keydown event multiple times: @HostListener('window:keydown', ...

Using the locale identifier en-GB can lead to date formats being displayed incorrectly

I'm struggling with setting up the correct locales in my Angular application. As per the documentation, I've inserted the following code snippet into my angular.json file. "projects": { "appname": { ..., "i18n&q ...

Problem with Angular2, NodeJS, and Passport Integration

At the moment, my Angular2 front-end is running on localhost:3000 while the NodeJS back-end (using KrakenJS) is running on localhost:8000. When I input the credentials and make a call to the this.http.post('http://localhost:8000/login', body, { h ...

When accessing an Angular 7 page directly through the URL in the browser, it becomes unresponsive. However, the page works perfectly fine when navigating

I've been tackling a poorly developed Angular 7 legacy application and encountering a bizarre issue. There's a component that requires a parameter for email verification, but when the URL is visited directly, it doesn't function as expected. ...

Issue encountered in Angular app-routing module.ts: Type error TS2322: The type '"enabled"' cannot be assigned to type 'InitialNavigation | undefined'

When I recently updated my project from Angular 11 to 14, I encountered the following error when running "ng serve". Error: src/app/app-routing.module.ts:107:7 - error TS2322: Type '"enabled"' is not assignable to type 'InitialNavigation | u ...

How can I retrieve JSON data that is specific to the selected item in an Ionic Angular application?

Exploring the world of ionic-angular framework, I have a home page with a modal embedded within it. The home page displays a list of items fetched from a JSON file, and upon clicking on a specific item, I wish to display all the information related to that ...

Can you provide details on the capabilities of Appium for webviews on Android devices?

I attempted to utilize the following capabilities { maxInstances: 1, browserName: '', appiumVersion: '1.18.2', platformName: 'android', platformVersion: '10.0', deviceName: 'd ...

Issue with offline functionality in Angular 8 PWA assetGroups

I developed a Progressive Web App using Angular 8.1.0, and I encountered an issue when testing it offline on my mobile device. The images and fonts in the asset groups are not loading properly. For instance, here is an error related to the logo image from ...

Directive encountered an error and could not be comprehended

Having an issue with an Angular5 directive I created in my app that is throwing an error. I'm struggling to pinpoint the problem, can anyone offer some assistance? Here's the code: import { Directive, ElementRef, HostListener, Input, Renderer } ...

Can a unique custom command be designed for the Kendo UI Grid in Angular2?

The built-in commands supported by the KendoUI Grid for Angular2 include: kendoGridAddCommand kendoGridCancelCommand kendoGridEditCommand kendoGridRemoveCommand kendoGridSaveCommand However, I am working on a project that requires a custom command to be ...

Angular service: Issue with updating value in observable property

Attempting to establish communication between two browser tabs/windows using the BroadcastChannel API. The communication appears to work between two instances of an angular service, but changes to the observable values are not reflected. I am attempting to ...

Invoking the callback function within the containing scope in Typescript

I am facing an issue with my Angular component where I have a class that includes common services and functions. While passing some functions as callbacks, the scope is getting lost during execution. Let me demonstrate the problem through the code below: @ ...