aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl
diff options
context:
space:
mode:
authorYen Chi Hsuan <yan12125@gmail.com>2016-02-17 06:01:44 +0800
committerYen Chi Hsuan <yan12125@gmail.com>2016-02-20 19:54:58 +0800
commit5bc880b9887c9689fef171683eae279adbbfc186 (patch)
treec5f19e816b4f1ebd8116262b62f24007f554ac52 /youtube_dl
parent958759f44b3e7c37509394568d9764e2794f713a (diff)
downloadyoutube-dl-5bc880b9887c9689fef171683eae279adbbfc186.tar.xz
[utils] Add OHDave's RSA encryption function
Diffstat (limited to 'youtube_dl')
-rw-r--r--youtube_dl/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 672ce05ea..7ce661b09 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -4,6 +4,7 @@
from __future__ import unicode_literals
import base64
+import binascii
import calendar
import codecs
import contextlib
@@ -2582,3 +2583,20 @@ class PerRequestProxyHandler(compat_urllib_request.ProxyHandler):
return None # No Proxy
return compat_urllib_request.ProxyHandler.proxy_open(
self, req, proxy, type)
+
+
+def ohdave_rsa_encrypt(data, exponent, modulus):
+ '''
+ Implement OHDave's RSA algorithm. See http://www.ohdave.com/rsa/
+
+ Input:
+ data: data to encrypt, bytes-like object
+ exponent, modulus: parameter e and N of RSA algorithm, both integer
+ Output: hex string of encrypted data
+
+ Limitation: supports one block encryption only
+ '''
+
+ payload = int(binascii.hexlify(data[::-1]), 16)
+ encrypted = pow(payload, exponent, modulus)
+ return '%x' % encrypted