当前位置: 首页>>代码示例>>Python>>正文


Python Cryptor.decrypt方法代码示例

本文整理汇总了Python中thumbor.crypto.Cryptor.decrypt方法的典型用法代码示例。如果您正苦于以下问题:Python Cryptor.decrypt方法的具体用法?Python Cryptor.decrypt怎么用?Python Cryptor.decrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thumbor.crypto.Cryptor的用法示例。


在下文中一共展示了Cryptor.decrypt方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: topic

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
 def topic(self):
     cryptor = Cryptor('my-security-key')
     for test in DECRYPT_TESTS:
         base_copy = copy.copy(BASE_PARAMS)
         base_copy.update(test['params'])
         encrypted = cryptor.encrypt(**base_copy)
         yield(cryptor.decrypt(encrypted), test['result'])
开发者ID:APSL,项目名称:thumbor,代码行数:9,代码来源:crypto_vows.py

示例2: test_thumbor_can_decrypt_lib_thumbor_generated_url

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
def test_thumbor_can_decrypt_lib_thumbor_generated_url():
    key = "my-security-key"
    image = "s.glbimg.com/et/bb/f/original/2011/03/24/VN0JiwzmOw0b0lg.jpg"
    thumbor_crypto = Cryptor(key)

    crypto = CryptoURL(key=key)

    url = crypto.generate(
        width=300,
        height=200,
        smart=True,
        image_url=image,
        old=True
    )

    reg = "/([^/]+)/(.+)"
    options = re.match(reg, url).groups()[0]

    decrypted_url = thumbor_crypto.decrypt(options)

    assert decrypted_url
    assert decrypted_url['height'] == 200
    assert decrypted_url['width'] == 300
    assert decrypted_url['smart']
    assert decrypted_url['image_hash'] == hashlib.md5(image).hexdigest()
开发者ID:gerasim13,项目名称:libthumbor,代码行数:27,代码来源:test_libthumbor.py

示例3: test_decrypting_combinations

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
def test_decrypting_combinations():
    cryptor = Cryptor('my-security-key')
    for test in DECRYPT_TESTS:
        base_copy = copy.copy(BASE_PARAMS)
        base_copy.update(test['params'])
        encrypted = cryptor.encrypt(**base_copy)
        yield decrypted_result_should_match, cryptor.decrypt(encrypted), test['result']
开发者ID:Bladrak,项目名称:thumbor,代码行数:9,代码来源:test_crypto.py

示例4: test_decrypting_with_wrong_key

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
    def test_decrypting_with_wrong_key(self):
        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs" \
            "U9wDzhqK9J_SHmpxDJHW_rBD8eilO26x2M_hzJfGB-V9cGF65GO_7CgJXI8Ktw188"

        cryptor = Cryptor(security_key="simething")
        wrong = cryptor.decrypt(encrypted_str)
        right = self.cryptor.decrypt(encrypted_str)
        expect(wrong['image_hash']).not_to_equal(str(right['image_hash']))
开发者ID:Bladrak,项目名称:thumbor,代码行数:10,代码来源:test_crypto.py

示例5: CryptoTestCase

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
class CryptoTestCase(TestCase):
    def setUp(self, *args, **kw):
        super(CryptoTestCase, self).setUp(*args, **kw)
        self.cryptor = Cryptor(security_key="something")
        self.cryptor.context = mock.Mock(
            config=mock.Mock(
                STORES_CRYPTO_KEY_FOR_EACH_IMAGE=False
            ),
        )

    def test_can_create_crypto_with_key(self):
        cryptor = Cryptor("key")
        expect(cryptor).not_to_be_null()
        expect(cryptor.security_key).to_equal("keykeykeykeykeyk")

    def test_can_encrypt(self):
        encrypted = self.cryptor.encrypt(
            width=300,
            height=300,
            smart=True,
            adaptive=False,
            full=False,
            fit_in=False,
            flip_horizontal=True,
            flip_vertical=True,
            halign="center",
            valign="middle",
            trim=True,
            crop_left=10,
            crop_top=11,
            crop_right=12,
            crop_bottom=13,
            filters='some_filter()',
            image="/some/image.jpg"
        )

        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs" \
            "U9wDzhqK9J_SHmpxDJHW_rBD8eilO26x2M_hzJfGB-V9cGF65GO_7CgJXI8Ktw188"

        expect(encrypted).to_equal(encrypted_str)

    def test_can_decrypt(self):
        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs" \
            "U9wDzhqK9J_SHmpxDJHW_rBD8eilO26x2M_hzJfGB-V9cGF65GO_7CgJXI8Ktw188"

        decrypted = self.cryptor.decrypt(encrypted_str)

        expect(decrypted).not_to_be_null()
        expect(decrypted).not_to_be_an_error()
        expect(decrypted).not_to_be_empty()
        expect(decrypted['width']).to_equal(300)
        expect(decrypted['height']).to_equal(300)
        expect(decrypted['smart']).to_be_true()
        expect(decrypted['fit_in']).to_be_false()
        expect(decrypted['horizontal_flip']).to_be_true()
        expect(decrypted['vertical_flip']).to_be_true()
        expect(decrypted['halign']).to_equal('center')
        expect(decrypted['valign']).to_equal('middle')
        expect(decrypted['crop']['left']).to_equal(10)
        expect(decrypted['crop']['top']).to_equal(11)
        expect(decrypted['crop']['right']).to_equal(12)
        expect(decrypted['crop']['bottom']).to_equal(13)
        expect(decrypted['filters']).to_equal('some_filter()')

        image_hash = hashlib.md5('/some/image.jpg').hexdigest()
        expect(decrypted['image_hash']).to_equal(image_hash)

    def test_decrypting_with_wrong_key(self):
        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs" \
            "U9wDzhqK9J_SHmpxDJHW_rBD8eilO26x2M_hzJfGB-V9cGF65GO_7CgJXI8Ktw188"

        cryptor = Cryptor(security_key="simething")
        wrong = cryptor.decrypt(encrypted_str)
        right = self.cryptor.decrypt(encrypted_str)
        expect(wrong['image_hash']).not_to_equal(str(right['image_hash']))

    def test_get_options(self):
        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs" \
            "U9wDzhqK9J_SHmpxDJHW_rBD8eilO26x2M_hzJfGB-V9cGF65GO_7CgJXI8Ktw188"
        image_url = "/some/image.jpg"

        expected_options = {
            'trim': 'trim', 'full': False, 'halign': 'center', 'fit_in': False,
            'vertical_flip': True, 'image': '/some/image.jpg',
            'crop': {'top': 11, 'right': 12, 'bottom': 13, 'left': 10},
            'height': 300, 'width': 300, 'meta': False, 'horizontal_flip': True,
            'filters': 'some_filter()', 'valign': 'middle', 'debug': False,
            'hash': 'e2baf424fa420b73a97476956dfb858f', 'adaptive': False, 'smart': True
        }
        options = self.cryptor.get_options(encrypted_str, image_url)
        expect(options).to_be_like(expected_options)

    def test_get_options_returns_null_if_invalid(self):
        encrypted_str = "hELdyDzyYtjXU5GhGxJVHjRvGrSP_iYKnIQbq_MuVq86rSObCeJvo2iXFRUjLgs"
        image_url = "/some/image.jpg"

        options = self.cryptor.get_options(encrypted_str, image_url)
        expect(options).to_be_null()

    def test_get_options_returns_null_if_different_path(self):
#.........这里部分代码省略.........
开发者ID:Bladrak,项目名称:thumbor,代码行数:103,代码来源:test_crypto.py

示例6: decrypt_in_thumbor

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
def decrypt_in_thumbor(key, encrypted):
    """Uses thumbor to decrypt libthumbor's encrypted URL"""
    crypto = Cryptor(key)
    return crypto.decrypt(encrypted)
开发者ID:wichert,项目名称:libthumbor,代码行数:6,代码来源:test_url_composer.py

示例7: decrypt_in_thumbor

# 需要导入模块: from thumbor.crypto import Cryptor [as 别名]
# 或者: from thumbor.crypto.Cryptor import decrypt [as 别名]
def decrypt_in_thumbor(url):
    '''Uses thumbor to decrypt libthumbor's encrypted URL'''
    encrypted = url.split('/')[1]
    cryptor = Cryptor(KEY)
    return cryptor.decrypt(encrypted)
开发者ID:julianwachholz,项目名称:libthumbor,代码行数:7,代码来源:test_cryptourl.py


注:本文中的thumbor.crypto.Cryptor.decrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。