示例#1
0
    def generate_new(self, options):
        url = plain_image_url(**options)
        _hmac = self.hmac.copy()
        _hmac.update(text_type(url).encode("utf-8"))
        signature = base64.urlsafe_b64encode(_hmac.digest()).decode("ascii")

        return f"/{signature}/{url}"
示例#2
0
    def generate_new(self, options):
        url = plain_image_url(**options)
        signature = base64.urlsafe_b64encode(hmac.new(b(self.key), text_type(url).encode('utf-8'), hashlib.sha1).digest())

        if PY3:
            signature = signature.decode('ascii')
        return '/%s/%s' % (signature, url)
示例#3
0
    def generate_new(self, options):
        url = plain_image_url(**options)
        signature = base64.urlsafe_b64encode(
            hmac.new(self.key,
                     unicode(url).encode('utf-8'), hashlib.sha1).digest())

        return '/%s/%s' % (signature, url)
示例#4
0
    def generate_new(self, options):
        url = plain_image_url(**options)
        _hmac = self.hmac.copy()
        _hmac.update(text_type(url).encode('utf-8'))
        signature = base64.urlsafe_b64encode(_hmac.digest())

        if PY3:
            signature = signature.decode('ascii')
        return '/%s/%s' % (signature, url)
示例#5
0
    def generate(self, **options):

        import urllib
        url = plain_image_url(**options)
        url = urllib.quote(url.encode('utf-8'), '/:?%=&()~",\'')

        signature = base64.urlsafe_b64encode(
            hmac.new(self.key,
                     unicode(url).encode('utf-8'), hashlib.sha1).digest())
        pad = lambda s: s + (32 - len(s) % 32) * "$"
        cypher = AES.new((self.key * 32)[:32])

        encrypted = base64.urlsafe_b64encode(
            cypher.encrypt(pad(url.encode('utf-8'))))

        return '/%s/%s.jpg' % (signature, encrypted)
示例#6
0
    def generate_new(self, options):
        url = plain_image_url(**options)
        signature = base64.urlsafe_b64encode(hmac.new(self.key, unicode(url).encode('utf-8'), hashlib.sha1).digest())

        return '/%s/%s' % (signature, url)
示例#7
0
 def generate_new(self, options):
     url = plain_image_url(**options)
     signature = base64.urlsafe_b64encode(hmac.new(self.key,
                                                   bytes(url, encoding='ascii'),
                                                   hashlib.sha1).digest())
     return '/%s/%s' % (str(signature, encoding='utf-8'), url)