Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About aes decrypt #12461

Closed
boygiandi opened this issue Mar 16, 2017 · 3 comments
Closed

About aes decrypt #12461

boygiandi opened this issue Mar 16, 2017 · 3 comments

Comments

@boygiandi
Copy link

@boygiandi boygiandi commented Mar 16, 2017

Hi.
I'm trying to convert an PHP video crawler script to youtube-dl (python). Link was encrypted by AES, I'm using this library in PHP to decrypt https://github.com/ivantcholakov/gibberish-aes-php .
It's very simple to use :

$media_url = GibberishAES::dec("U2FsdGVkX1/v3lNRMc7N7chKwkk89sjJr5xu4SLxC8DzV+DN9aZEelQ0jJcOcYg+I4KDLfgPPKAk28LpSmsqMFGYjPfn0684hKx+gfk4r9uyLoiiXs2eEsPaSEy06p+BV1QNQJuoykIpDZkeV0zWXKaqZhkz4iwHGTsMzxAFkIEvsd4JVe1JVapnTklCYRfLOt7tlkFTqfKxCpIaQFqe7hz0eLW3rPcfEk6ASBE7ue8/ETe/ziEAlH3k1D6zt6c7lb1wNtWMTIIuFGkrKV5WanKQwezMQ0ywsBe76jOR1DkynU62pJU/CUMtcprYhz0HzNHy8JKyji22uUIyskmZ6Ehk2tNJtStA0Yyq4B/u9e/PmGYJsfUEDW5M3XSQIGGHCS89o/LtELl4TlzdhcfsZbCl6BR+q8zOE+hYt9fRfhSuJOVT8bv1rN2AaQRydZBrGtBENUR12MzwERQasg9po/6WhVJyiKb+2cuOebJlkXt11bw20wsFTRgnTNlL6he9McHwtvDwRgspHHVmcTIv/Q4h2g8khfY2L5NmFf0smgdQoMey1sDezuoowNIrRnJKN5ysJ/Np3B+G+9HCLVJDwBwt91wm89/CWOSsTP0iuT7bDerL8ezWdLehiCJfD6r/9EJwlyPqtARewNLth56k1y3UFuOu/le9BAMTixiEIWU=", 'phimbathu.com45904818776707');

Result

https://redirector.googlevideo.com/videoplayback?id=c497980b7f982b0b&itag=18&source=webdrive&requiressl=yes&ttl=transient&mm=30&mn=sn-i3b7kn7y&ms=nxu&mv=u&pl=48&ei=hczJWPSYOcvoqQX81quACg&mime=video/mp4&lmt=1487699254560815&mt=1489619994&ip=2001:ee0:305:1::16&ipbits=0&expire=1489634502&sparams=ip,ipbits,expire,id,itag,source,requiressl,ttl,mm,mn,ms,mv,pl,ei,mime,lmt&signature=5F649791D284F0816D2E0C088CC32E3D85435CD5.417A9FA3CAD7FB623AEA310F08A72699C7DFD74C&key=ck2&app=explorer

But when I use aes_decrypt_text in youtube-dl with the same params, it show error

print aes_decrypt_text("U2FsdGVkX1/v3lNRMc7N7chKwkk89sjJr5xu4SLxC8DzV+DN9aZEelQ0jJcOcYg+I4KDLfgPPKAk28LpSmsqMFGYjPfn0684hKx+gfk4r9uyLoiiXs2eEsPaSEy06p+BV1QNQJuoykIpDZkeV0zWXKaqZhkz4iwHGTsMzxAFkIEvsd4JVe1JVapnTklCYRfLOt7tlkFTqfKxCpIaQFqe7hz0eLW3rPcfEk6ASBE7ue8/ETe/ziEAlH3k1D6zt6c7lb1wNtWMTIIuFGkrKV5WanKQwezMQ0ywsBe76jOR1DkynU62pJU/CUMtcprYhz0HzNHy8JKyji22uUIyskmZ6Ehk2tNJtStA0Yyq4B/u9e/PmGYJsfUEDW5M3XSQIGGHCS89o/LtELl4TlzdhcfsZbCl6BR+q8zOE+hYt9fRfhSuJOVT8bv1rN2AaQRydZBrGtBENUR12MzwERQasg9po/6WhVJyiKb+2cuOebJlkXt11bw20wsFTRgnTNlL6he9McHwtvDwRgspHHVmcTIv/Q4h2g8khfY2L5NmFf0smgdQoMey1sDezuoowNIrRnJKN5ysJ/Np3B+G+9HCLVJDwBwt91wm89/CWOSsTP0iuT7bDerL8ezWdLehiCJfD6r/9EJwlyPqtARewNLth56k1y3UFuOu/le9BAMTixiEIWU=", 'phimbathu.com45904818776707', 32).decode('utf-8')

File "/usr/lib64/python2.7/encodings/utf_8.py", line 16, in decode return codecs.utf_8_decode(input, errors, True) UnicodeDecodeError: 'utf8' codec can't decode byte 0xad in position 1: invalid start byte

Please help me.

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Mar 16, 2017

From aes.py:

Mode of operation is 'counter'

youtube-dl's aes_decrypt_text uses CTR mode, and gibberish-aes-php uses CBC. You can call aes_cbc_decrypt instead.

@yan12125 yan12125 closed this Mar 16, 2017
@boygiandi
Copy link
Author

@boygiandi boygiandi commented Mar 16, 2017

aes_cbc_decrypt(data, key, iv)

In this case, can you show me what is iv ?

aes_cbc_decrypt("....base 64string....", "phimbathu.com45904818776707", iv)

Thanks

@yan12125
Copy link
Collaborator

@yan12125 yan12125 commented Mar 16, 2017

Gibberish's function uses a custom IV value: https://github.com/ivantcholakov/gibberish-aes-php/blob/master/GibberishAES.php#L164

By the way, aes_cbc_decrypt uses int lists, so you need intlist_to_bytes and bytes_to_intlist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.