Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

278
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda