3

I wrote a program to use chrome's login cookies to do something automatically, but since Chrome encrypt all the cookies at January, my program can't work anymore.

I'm trying to decrypt cookies, and success in java on mac os by This Topic, but my usual running environment is win7 os, so I have to decrypt that on windows.

I found os_crypt_win.cc in Chromium's source code, it has a encrypt part:

bool OSCrypt::EncryptString(const std::string& plaintext, std::string* ciphertext) {
  DATA_BLOB input;
  input.pbData = const_cast<BYTE*>(reinterpret_cast<const BYTE*>(plaintext.data()));
  input.cbData = static_cast<DWORD>(plaintext.length());

  DATA_BLOB output;
  BOOL result = CryptProtectData(&input, L"", NULL, NULL, NULL, 0, &output);
  if (!result)
    return false;

  // this does a copy
  ciphertext->assign(reinterpret_cast<std::string::value_type*>(output.pbData), output.cbData);

  LocalFree(output.pbData);
  return true;
}

I imitate this part in java with JNA:

String encrypted = bytesToHex(Crypt32Util.cryptProtectData(Native.toByteArray(plaintext), 0));

or

String encrypted = bytesToHex(Crypt32Util.cryptProtectData(plaintext.getBytes());

or

String encrypted = bytesToHex(Crypt32Util.cryptProtectData(plaintext.getBytes("UTF-8"));

or

String encrypted = bytesToHex(Crypt32Util.cryptProtectData(plaintext.getBytes("UTF-16"));

But I got a wrong encrypted values different with the value store in Chrome.

Did I used a wrong method to encrypt this, or did I miss something important?

Can you help me figure this out?

Community
  • 1
  • 1
Morshues
  • 125
  • 1
  • 12

1 Answers1

1

You used the correct method to encrypt the values. How are the values "wrong"? if they are just different from the one's stored in chrome that is not a problem. The reason for that is very simple:

from msdn:

"The function creates a session key to perform the encryption. The session key is derived again when the data is to be decrypted."

from msdn blog:

"A random session key is created for each call to CryptProtectData. This key is derived from the master key, some random data, and some optional entropy passed in by the user. The session key is then used to do the actual encryption."

The important thing you should check is whether you are able to decrypt the values using DecryptUnprotectData.

Simonos
  • 31
  • 4