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.2.tar.gz (51.9 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.2-py3-none-any.whl (60.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nbclass-1.5.2.tar.gz
  • Upload date:
  • Size: 51.9 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.2.tar.gz
Algorithm Hash digest
SHA256 6c7b6637353c541892b689a2e20896deef497006713a1d94f876fb97e6d31700
MD5 d26531e7ba79f2e1100f4ee6d7682706
BLAKE2b-256 ec017d64ef7c42269cc6607b7f64292d1520371fd9144aca37b66f7fca4e4030

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nbclass-1.5.2-py3-none-any.whl
  • Upload date:
  • Size: 60.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 21cc3799c12f6a933ba1352966438395ca4c18f8f8ea2243323113ccb607b7a1
MD5 f1f4782f0bdbdf63c459127de05ec0e4
BLAKE2b-256 0669bcf3b05020cae63cdf9f9f37ac9258f8e51249360e6cdb1476a750fecdc2

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