Skip to main content

encrypt basic openssl

Project description

random_encrypt

基于openssl加密

仅使用了 AES-128-CBC

根据时间戳所在的时间区间,时区信息计算加密的key,iv

为每个key设置有效时间(默认5秒,冗余2秒),在不同的时间区间(左包右闭),相同文本加密后的字符串不同

默认时区为东八区,加密端和解密端通过统一时区对齐时间,避免不同时区,同时间段,加密后的密文不同,导致无法解密

在使用时,必须自定义盐值,不能为空。

if self._salt == "":
    raise Exception('the salt can not be empty.')

Encrypt函数返回 (加密后字符串,key,iv,加密时使用的时间戳) 供解密失败后备查。

Install

pip install random_tool

示例代码:

from random_encrypt import RandomEncrypt

if __name__ == '__main__':
    e = RandomEncrypt({"salt": "salt"})
    s = e.encrypt("hello world")
    print(s)
    t = e.decrypt(s[0])
    print(t)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

random_tool-1.0.1.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

random_tool-1.0.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file random_tool-1.0.1.tar.gz.

File metadata

  • Download URL: random_tool-1.0.1.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for random_tool-1.0.1.tar.gz
Algorithm Hash digest
SHA256 06a07a0b84f47242f15e949645a3d20f3d4028604234b682f0c503428b2c2fc3
MD5 1ea97172d29a93f637eb9235e744938f
BLAKE2b-256 3b86cc32bdc74de507a93e39b2407a2873202957185ef9d34799ab4e72d359ff

See more details on using hashes here.

File details

Details for the file random_tool-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: random_tool-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for random_tool-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9703c8655c6917b31fd08e03904f7aded1ebe7a0a3b7371e0cee7b5facfdad7b
MD5 89829f8fdd758dee790753cf45ec0109
BLAKE2b-256 02c1b9afc352423a7cc50741c34a1898ff020f78989c7c5f3fec359327769a86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page