What are some alternatives if slowAES isn't functioning properly with CBC/PKCS7?

Is there a way to encrypt data in javascript using CBC/PKCS7 so that it can be decrypted in php or .NET?

I've experimented with slowAES, but the encrypted output doesn't seem to be correct.

When I compare slowAES and .NET encryption using the same input byte arrays (key, iv, and message), slowAES produces a different output byte array.

Comparing the results with .NET and php's mcrypt, they generate the same output.

I attempted to apply the fix suggested in this link, but it didn't resolve the issue.

If this is indeed a problem with slowAES, does anyone know of a functional alternative or how to address it?

On a side note, I am able to successfully encrypt and decrypt when only using slowAES.


Update: Here's an example:

JavaScript Encryption:

var bytesToEncrypt = cryptoHelpers.convertStringToByteArray("2|2010-11-23+10:04:53|0");

var key = cryptoHelpers.base64.decode("de1310982b646af063e7314e8ddd4787");

var iv = cryptoHelpers.base64.decode("v/VCTAlV5+kexBFN16WY5A==");

var result = slowAES.encrypt(bytesToEncrypt, 
slowAES.modeOfOperation.CBC,
key,
slowAES.aes.keySize.SIZE_128,
iv);

return result['cipher'];

.NET/Silverlight Encryption:

    class AES
    {
        AesManaged aes;

        public AES(string base64key, string base64IV) 
            : this(Convert.FromBase64String(base64key),Convert.FromBase64String(base64IV)) 
        {}

        public AES(byte[] key, byte[] iv)
        {
            // CBC/128/PKCS7
            aes = new AesManaged();
            aes.Key = key;
            aes.IV = iv;
        }
        public string Encrypt(string strInptData)
        {
            byte[] utfdata = UTF8Encoding.UTF8.GetBytes(strInptData);

            // Create a decrytor to perform the stream transform.
            ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, aes.IV);

            // Create the streams used for encryption.
            MemoryStream msEncrypt = new MemoryStream();
            CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write);

            csEncrypt.Write(utfdata, 0, utfdata.Length);
            csEncrypt.Flush();
            csEncrypt.Close();

            // Showing our encrypted content
            byte[] encryptBytes = msEncrypt.ToArray();

            return HttpUtility.UrlEncode(Convert.ToBase64String(encryptBytes));
        }
    }

string base64key = "de1310982b646af063e7314e8ddd4787";
string base64iv = "v/VCTAlV5+kexBFN16WY5A==";

aes = new AES(base64key, base64iv);

auth_token = aes.Encrypt("2|2010-11-23+10:04:53|0");

The comparison reveals that .NET and JavaScript produce different byte arrays, indicating that the issue may not be related to base64/url encoding/decoding.

Answer №1

Your confidential passcode is a length of 24 bytes (192 bits), however, you have mistakenly stated that it is only 16 bytes (128 bits):

var result = slowAES.encrypt(bytesToEncrypt, 
slowAES.modeOfOperation.CBC,
key,
slowAES.aes.keySize.SIZE_128, // <- This is where the issue lies
iv);

Simply switch SIZE_128 to SIZE_192, and everything should function correctly. I have developed a Java application that generates identical results to your JavaScript illustration.

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

Automatically submitting a form in the absence of the user from the page

Is it possible to automatically submit a form when the user exits the page? Here's the code snippet: <form class="carform" method="get"> <input type="hidden" name="number_plate" value="{{ car.number_plate }}"> </form> I want the ...

I am experiencing some difficulties with my animation in three js. Despite clicking on the button, the animation does not seem to play. What could

My goal is to create an animation where boxes move when the start button is clicked. However, I am facing an issue where clicking the start button does not initiate any movement in the boxes. Could someone help me identify and solve this problem? For ref ...

Utilizing sourcemaps in ionic for seamless linking

I've encountered an issue with source maps or a similar feature. After inserting console.log(...) in my code, the message appears in the console but links to the compiled JavaScript file instead of the original TypeScript file. Have I overlooked som ...

The issue persists with the Javascript AJAX POST Method as it fails to transmit values to the designated

I have been using Javascript AJAX to make a request to a php page and receive the output from that page. Interestingly, when I use the GET method in my AJAX call, everything works as expected. However, the issue arises when I try to use the POST method. B ...

Web browser local storage

Looking to store the value of an input text box in local storage when a button is submitted <html> <body action="Servlet.do" > <input type="text" name="a"/> <button type="submit"></button> </body> </html> Any sug ...

Optimal approach for integrating an ionic mobile app with Django to streamline form processing

Currently in the process of developing a mobile application with ionic technology. In the case of a traditional django website, we typically create context within the view and pass it to the template, where the HTML is displayed using various methods such ...

Modifying the temp variable by assigning a new value to this.value in Javascript

Using a temporary variable, I initialize a THREE.Vector3 which is then passed into the creation of an object. object[i] = new Object(new THREE.Vector3(0,0,0)); Within the Object class, there is a variable called texture that gets assigned the new THREE.V ...

IIS Alert: Missing Images, CSS, and Scripts!

When I tried to publish my website using IIS, I encountered the error message Cannot read configuration file due to insufficient permissions. After attempting to add permissions for IIS_USRS and realizing that this user does not exist on my computer runnin ...

Can you please help me find the location of the message "Warning: this function is designed for client-side use only and will not work on the server side" in React/Node?

I have a project using expressjs and react that I want to gradually make isomorphic. I'm taking baby steps in the process, but I'm struggling to pinpoint where certain logs, such as: "Warning: the function is client-side only, does not work on ...

Using JavaScript to Compare Time with AM/PM Formats

Consider the following two strings: var x = "01/15/2022 6:30 AM" var y = "01/14/2022 4:45 PM" In JavaScript, how can I compare these strings to demonstrate that the time for var y occurs earlier than var x? ...

Exploring the implementation of if statements within the array map function in the context of Next.js

Is there a way to wrap certain code based on the remainder of the index number being 0? I attempted the following approaches but encountered syntax errors. {index % 3 === 0 ? ... : ...} {index % 3 === 0 && ...} export default function UserPosts() { / ...

Updating a form submit does not retain the value of the JQueryUI Progress Bar

I am currently working on setting up a JQuery Progress Bar that updates when the user submits a form. The code I am debugging is basic and consists of: <body> <form id="form1" method="GET" runat="server"> <div> <h1>Test</h1& ...

What is the process of decoding a URL in JavaScript?

Is there a better method to decode this URL in order to use it with JavaScript? URL: https://www.example.com/post.php?v=1&text=it's-me&20hello%0Aworld%0A At present, any occurrence of ' in the URL is causing an error and blank lines ar ...

Guide to locating the index of a div element that has been dropped onto a droppable div

My web application features drag and drop functionality allowing users to drag a div and dynamically drop it onto a droppable area. Additionally, the droppable area has sortable functionality enabled. Now, I need to determine the indexing in order to acc ...

Executing javascript after an AJAX call within an on() method: Tips and tricks

I am struggling to make a $.ajax() call within a function triggered by the .on() method, in order to execute a script on a .click() event after updating newly appended data. I have tried numerous times to troubleshoot, but I can't seem to pinpoint the ...

Guide on setting a wait while downloading a PDF file with protractor

As I begin the download of a pdf file, I realize that it will take more than 2 minutes to complete. In order to verify if the file has successfully downloaded or not, I will need to wait for the full 2 minutes before performing any verification checks. C ...

Can I use MuiThemeProvider in my component without any restrictions?

I have a unique component called View: import React from 'react'; import { AppBar, Toolbar } from 'material-ui'; import { Typography } from 'material-ui'; import { MuiThemeProvider, createMuiTheme } from 'material-ui/st ...

Trigger the next button click event using jQuery

Is it possible to implement a slideshow on my website where clicking a button displays the relevant slide? My goal is to incorporate a timer that will automatically click the next button after 3 seconds, enabling the slideshow to transition automatically. ...

A method for setting a value from an HTML textbox to a variable and displaying it on the same page

How can I retrieve the value from a textbox and display it on the same page? The purpose behind this is that when the user enters their BTC wallet into the textbox, I want to store this value in a variable on the same page and then output the value. I at ...

If the URL matches a specific path, then append a parameter

I've created a script that adds a parameter to a URL based on specific subfolders. For example, if the URL contains /de, it will add ?_sft_language=german. However, I'm encountering an issue where the code is running multiple times instead of jus ...