Open fancy45daddy opened 1 month ago
@fancy45daddy were you able to figure this out I also want the same information to write the code in native module
How come you’re doing that ?Sent from my iPhoneOn Sep 24, 2024, at 3:51 AM, nikhiltekwani09 @.***> wrote: @fancy45daddy were you able to figure this out I also want the same information to write the code in native module
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: @.***>
I m not sure right now, till I have the complete information which @fancy45daddy is requesting
I am trying to decrypt encrypted content using a backend in a different language, and I solved this problem today. When you enter the Secret Passphrase, crypto-js consistently uses AES-256-CBC for encryption. The first 16 bytes of the encrypted content are related to the Salt. The first 8 bytes are a verification flag, which is fixed as 'Salted__', and the next 8 bytes are the actual Salt. Then, crypto-js simulates the OpenSSL EVP_bytesToKey function (evpkdf) and performs an MD5 hash on the Key and Salt. For the specific implementation, please refer to the compute function in evpkdf.js. This calculates a 48-byte data output, where the first 32 bytes are the key and the last 16 bytes are the IV.
from the doc var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase"); encrypted.key
i have no idea how to get key and iv, then i ask chatgpt, it give me some code
// Define passphrase and salt const passphrase = 'your-passphrase'; const salt = CryptoJS.enc.Hex.parse('your-salt-in-hex'); // Salt should be in a suitable format
// Derive key and IV using PBKDF2 const keySize = 256 / 32; // Key size in words const ivSize = 128 / 32; // IV size in words const iterations = 1000; // Number of iterations
// Derive key const key = CryptoJS.PBKDF2(passphrase, salt, { keySize: keySize + ivSize, // Total size for key and IV iterations: iterations });
// Extract key and IV const derivedKey = CryptoJS.lib.WordArray.create(key.words.slice(0, keySize)); // Extract key const iv = CryptoJS.lib.WordArray.create(key.words.slice(keySize)); // Extract IV
but when i input the passphrase and salt in chatgpt code. it does not create the same key as that in encrypted.key and encrypted.iv. plèase help me to understand how to get key and iv