Skip to main content

nbclass工具包

Project description

NBCLASS

环境要求:

  • Python 3.6.0+
  • Works on Linux, Windows, macOS

安装

From PyPi:

pip install nbclass

更新

1.4版本

  • 1.4 添加装饰器
  • 1.4.6 更新数据库查询, 哈希加密工具
  • 1.4.7 添加AES加解密工具
from nbclass import tools

key = '1234567890123456'
print(tools.aes_encrypt_cbc(key, '人生苦短我用python', key))  # => YkeE6FB0FhZaXYsj+AYWMiTJDdOJS4g1EQzZ1WRN2DQ=
print(tools.aes_encrypt_cbc(key, '人生苦短我用python', key, is_hex=True))  # => 624784e8507416165a5d8b23f806163224c90dd3894b8835110cd9d5644dd834
  • 1.4.8 添加Hmac加解密方法
from nbclass import tools

tools.get_hmac_md5('123456', '人生苦短我用python')
tools.get_hmac_sha1('123456', '人生苦短我用python')
tools.get_hmac_sha256('123456', '人生苦短我用python')
tools.get_hmac_sha256('123456', '人生苦短我用python')

1.5版本

  • 1.5.0 添加账号管理池
from typing import Optional

from nbclass.db.mysqldb import MysqlDB
from nbclass.db.redisdb import RedisDB
from nbclass.decorators import singleton
from nbclass.network.user_pool import NormalUser
from nbclass.network.user_pool import NormalUserPool


@singleton
class MysqlDB1341(MysqlDB):

    def __init__(self):
        super().__init__(
            ip='192.168.1.110',
            port=3306,
            db='test',
            user_name='python',
            user_pass='123456975.20',
        )


class RedisDB28(RedisDB):

    def __init__(self, db=0):
        super().__init__(
            ip_ports='192.168.2.28:6379',
            db=db,
            user_pass='feapderYYDS'
        )


class TestGuestUserPool(NormalUserPool):

    def login(self, user) -> Optional[NormalUser]:
        user = NormalUser(
            user_id=user.user_id,
            username=user.username,
            password=user.password,
            token='CAOJrYvo0VINfMyMKXeIUcNlDhteJfQk_uIg_bIeCj65b0XLJbIxoNiuIPIIle2FAbhQ_V6TklV5pwNcSTirqQ',
            mobile=None
        )
        return user


if __name__ == '__main__':
    user_pool = TestGuestUserPool(
        redis_cli=RedisDB28(db=1),
        mysql_cli=MysqlDB1341(),
        redis_key="python:mtUserPool",
        table_userbase='py_user_pool',
        keep_alive=True,
    )
    users = user_pool.get_user()
    print("取到user:", users)

1.5版本

  • 1.5.1 增加国密算法
from nbclass.encrypt import CryptSM2
# sm2签名
sm2 = CryptSM2(private_key='', public_key='')
msg = 'bf9e57456f0bb709471783fa1aad8a3b7f1bef38'
sign = sm2.sign(msg, '123456789abcdef')
verify = sm2.verify(sign, msg)
print(sign)
print(verify)

# sm2加解密
ciphertext = sm2.encrypt(msg)
print(ciphertext.hex())
plaintext = sm2.decrypt(ciphertext, is_hex=True)
print(plaintext)

from nbclass.encrypt.sm3 import sm3_hash
print(sm3_hash('123456'))

# sm4
from nbclass.encrypt.sm4 import CryptSM4 as Sm4, EncodeType
key = '132F8664322CBA13142E21161297AD91'
data = '123456789'

s4 = Sm4(key)
cbc = s4.encrypt_cbc(iv=key, msg=data).hex()
ecb = s4.encrypt_ecb(msg=data).hex()
print('cbc加密', cbc)
print('ecb加密', ecb)

cbc_d = s4.decrypt_cbc(iv=key, msg=cbc, input_type=EncodeType.HEX)
ecb_d = s4.decrypt_ecb(msg=ecb, input_type=EncodeType.HEX)
print('cbc解密', cbc_d)
print('ecb解密', ecb_d)

爬虫工具推荐

  1. 爬虫在线工具库:http://www.spidertools.cn
  2. 验证码识别库:https://github.com/sml2h3/ddddocr

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

nbclass-1.5.1.tar.gz (51.2 kB view details)

Uploaded Source

Built Distribution

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

nbclass-1.5.1-py3-none-any.whl (59.4 kB view details)

Uploaded Python 3

File details

Details for the file nbclass-1.5.1.tar.gz.

File metadata

  • Download URL: nbclass-1.5.1.tar.gz
  • Upload date:
  • Size: 51.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.16

File hashes

Hashes for nbclass-1.5.1.tar.gz
Algorithm Hash digest
SHA256 ec57a8f206e8a538d7fd4e419d2fff0962ac9f10b37a8b6f8896568ab1596efd
MD5 c6351c8e7d8353a0c97889c0ea3a3cdf
BLAKE2b-256 7d69cd1ff6c0168c0309c9783ce7233f9d7d23ead40c03aea0c4ebb54f6ca94c

See more details on using hashes here.

File details

Details for the file nbclass-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: nbclass-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 59.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.8.16

File hashes

Hashes for nbclass-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 40d4ca4f88bcd1440c72ce1e5bab14dc461884857c45eaca56be40d1fd6074d4
MD5 b1def6141a0dce62821effbf04bcd990
BLAKE2b-256 871b1e4ff8a491d7801ab12823afff3c6c5c529fb70e045a05acc23a62bfcd1e

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