Search code examples
encryptionaesevernotepbkdf2cbc-mode

In note text encrypted data structure in Evernote


I'm author of a couple evernote extensions, and I wan't to utilize encrypted text, create them on my end and add to a note using the enml structure and en-crypt.

however, I'm unable to figure out the structure of an en-crypt CDATA.

If you look at the .enex file after exporting the note, the enml element of an encrypted text looks like this:

<en-crypt hint="My Cat's Name">NKLHX5yK1MlpzemJQijAN6C4545s2EODxQ8Bg1r==</en-crypt>

I've read through this https://help.evernote.com/hc/en-us/articles/208314128-What-type-of-encryption-does-Evernote-use which explains that the key is derived with PBKDF2 and the encryption is done with unique salt aes-cbc 256bit method, however, looking at the example above, I'm unable to figure out how that data is stored there.

If I count correctly, There are two unique salts and one IV, as well as the encrypted text to store there. So my question is, how can one make use of that block? There might be a standard way of storing all that information in one base64 block. But I'm no encryption expert so any bit of help is appreciated.

Thanks.


Solution

  • For old, RC2-based encryption (and if your <en-crypt> tag doesn't have the cipher="AES" attribute, this is the RC2-based encryption), the algorithm roughly looks like this:

    decodedString = RC2.decrypt(Base64.decode(encodedString), MD5.hash(UTF8.encode(passphrase)), 64);

    In the decoded string, the first 4 chars of the string is the HEX-representation of the upper-byte of the CRC32 of the rest of the decoded string.

    One caveat: when calculating CRC32, you may need to XOR it with -1 (0xFFFFFFFF) as there are different implementations of CRC32 in the wild that may or may not do this final XOR.