cryptojs-extension icon indicating copy to clipboard operation
cryptojs-extension copied to clipboard

How I can contiuned use update?

Open ying2025 opened this issue 6 years ago • 3 comments

I want use it like this picture.

image The code is:

 function test3() {
     let vec = {
        key: "8395FCF1E95BEBD697BD010BC766AAC3",
        nonce: "22E7ADD93CFC6393C57EC0B3C17D6B44",
        header: "126735FCC320D25A",
        msg: "CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7",
        msg2: "6CF36720872B8513F6EAB1A8A44438D5EF11",
        ct: "CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E"
    };
    let keyBytes = CryptoJS.enc.Hex.parse(vec.key),
        msgBytes = CryptoJS.enc.Hex.parse(vec.msg),
        msgBytes2 = CryptoJS.enc.Hex.parse(vec.msg2),
        nonceBytes = CryptoJS.enc.Hex.parse(vec.nonce),
        headerBytes = CryptoJS.enc.Hex.parse(vec.header);   
    let eax = CryptoJS.EAX.create(keyBytes);
    eax.encrypt(nonceBytes, [headerBytes]);
    eax.update(msgBytes);
    eax.update(msgBytes2);
    let et = eax.finalize();
    // console.log(et.toString())
    console.log("msgB1 ",vec.msg.toLowerCase(), "ciphertext match ["+"]");

}.

image image

image image

ying2025 avatar Sep 03 '18 02:09 ying2025

@ying2025 I don't see how having encrypt and update+finalize makes sense semantically. encrypt is complete and closed operation, whereas create+updateAAD+initCrypt+update+finalize is the fully self-managed way to do encrypt. If you want to combine updateAAD+initCrypt, why not call it prepareEncryption or even combine create+updateAAD+initCrypt and overwrite create or call it createAndInit? The latter would need to call the inherited function from the underlying framework somehow.

artjomb avatar Sep 03 '18 20:09 artjomb

Yes, you are right. I have modified it. But now I continuously use update, the message can decrypt correctly, but ext.equals(self._tag, self._buf) == false. If it use multiple update, I put the encrypt data to the self.xoredData avoiding being covered. I don't konw whether it right, and how to deal the last block. image

image

And M_i is diffierent when update in encrtpt and update in decrypt. image

ying2025 avatar Sep 04 '18 08:09 ying2025

I change the postion of self._mac.update for message, and it can decrypt rightly, but I don't konw whether it have any problems. image

ying2025 avatar Sep 06 '18 03:09 ying2025