Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

269
Views
How to decrypt AES SubtleCrypto [window.subtle.crypto] at CryptoJS

I'm attempting to migrate from Browser-only window.subtle.crypto to CryptoJS so it is universally available across all platforms using Expo.

Essentially: window.subtle.encrypt({name: AES-GCM}) -> CryptoJS.AES.decrypt

For the existing data encrypted, CryptoJS should be able to decrypt it utilizing the AES generated key from window.subtle.generateKey, so the method for window.subtle.encrypt cannot be changed and it's being done as described below

I want to decrypt the window.subtle.encrypt encrypted at CryptoJS's CryptoJS.AES.decrypt

so for this, I've written this test code:

const text = "This is an encrypted message";

const generateKey = async () => {
    const key = await window.crypto.subtle.generateKey({ name: "AES-GCM", length: 128 }, true, ["encrypt", "decrypt"]);
    const key_exported = await window.crypto.subtle.exportKey("jwk", key);
    return key_exported.k;
}

const printCurrent = async () => {
        let kkey = await generateKey();
        await window.crypto.subtle.importKey(
            "jwk",
            {
                k: kkey,
                alg: "A128GCM",
                ext: true,
                key_ops: ["encrypt", "decrypt"],
                kty: "oct",
            },
            { name: "AES-GCM", length: 128 },
            false,
            ["encrypt", "decrypt"]
        ).then(function(key){
            window.crypto.subtle.encrypt({ name: "AES-GCM", iv: new Uint8Array(12) }, key, new TextEncoder().encode(JSON.stringify(text))).then( function(encryptedObject){
            const cryptojs = CryptoJS.AES.decrypt(encryptedObject,key,{iv: new Uint8Array(12));
            console.log("cryptojs: ", cryptojs.toString(CryptoJS.enc.Utf8));
            });
        } );
    }
    printCurrent();

I've seen that CryptoJS accepts only WordArray, and the output of the encrypted object ['encryptedObject'] from subtle crypto is ArrayBuffer [46 size], I've tried converting ArrayBuffer to WordArray via CryptoJS.lib.WordArray.create(encryptedObject) but still no luck.

Any help or guidance is appreciated, thanks so much!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!