Skip to content

Commit

Permalink
Decryption issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hellc committed Jan 15, 2023
1 parent 075a6dd commit 87dda3f
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions pandas_datareader/yahoo/daily.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@

def decrypt_cryptojs_aes(data):
encrypted_stores = data["context"]["dispatcher"]["stores"]
_cs = data["_cs"]
_cr = data["_cr"]

_cr = b"".join(
int.to_bytes(i, length=4, byteorder="big", signed=True)
for i in json.loads(_cr)["words"]
)
password = hashlib.pbkdf2_hmac("sha1", _cs.encode("utf8"), _cr, 1, dklen=32).hex()
password_key = next(key for key in data.keys() if key not in ["context", "plugins"])
password = data[password_key]

encrypted_stores = b64decode(encrypted_stores)

assert encrypted_stores[0:8] == b"Salted__"
salt = encrypted_stores[8:16]
encrypted_stores = encrypted_stores[16:]
Expand Down Expand Up @@ -229,11 +224,9 @@ def _read_one_data(self, url, params):
try:
j = json.loads(re.search(ptrn, resp.text, re.DOTALL).group(1))

if "_cs" in j and "_cr" in j:
new_j = decrypt_cryptojs_aes(
j
) # returns j["context"]["dispatcher"]["stores"]
# from old code
new_j = decrypt_cryptojs_aes(
j
)

data = new_j["HistoricalPriceStore"]

Expand Down

0 comments on commit 87dda3f

Please sign in to comment.