Skip to main content

基于pycryptodomex的二次封装,对CryptoJS的AES和CBC进行了简单的复刻

Project description

介绍

这是一个crypto-js的Python复刻版,对ECB和CBC进行了简单的复刻

安装与导入

pip install crypto-js-to-py
from crypto_py import CryptoPY

代码示例

  • 一个简单的crypto-js移植python的示例代码

    • 这是一段crypto-js的示例代码

      const CryptoJS = require("crypto-js")
      
      key = CryptoJS.enc.Utf8.parse("1234567890123456")
      iv = CryptoJS.enc.Utf8.parse("1234567890123456")
      data = "我是帅哥"
      
      encrypt = CryptoJS.AES.encrypt(data,key,{
          "iv": iv,
          "mode":CryptoJS.mode.CBC,
          "padding":CryptoJS.pad.Pkcs7
      }).toString()
      
      console.log(encrypt)
      
    • 这是移植到python的代码

      from crypto_py import CryptoPY as CryptoJS
      
      # 以下操作都相同
      key = CryptoJS.enc.Utf8.parse("1234567890123456")
      iv = CryptoJS.enc.Utf8.parse("1234567890123456")
      data = "我是帅哥"
      
      # 这里的options也可以通过对象的方式传入
      # options = CryptoJS.Options(
      #     iv=iv,
      #     mode=CryptoJS.mode.CBC,
      #     padding=CryptoJS.pad.Pkcs7
      # )
      # encrypt = CryptoJS.AES.encrypt(data,key,options).decode()
      
      
      encrypt = CryptoJS.AES.encrypt(data,key,{
          "iv": iv,
          "mode":CryptoJS.mode.CBC,
          "padding":CryptoJS.pad.Pkcs7
      }).decode()
      
      print(encrypt)
      
  • 同时也支持NoPadding和ciphertext

    • CryptoPY.pad.NoPadding 暂时未能测试是否无BUG
    • CryptoPY.AES.encrypt(...).ciphertext.decode()
    • CryptoPY.AES.decrypt(...).ciphertext.decode()

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

crypto-js-to-py-0.2.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

crypto_js_to_py-0.2.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file crypto-js-to-py-0.2.1.tar.gz.

File metadata

  • Download URL: crypto-js-to-py-0.2.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for crypto-js-to-py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e8b08d91c0e0dd6ec2293dd3a59c4b1aeaad310c49ef3a04aa5611e2b10238dd
MD5 2c9de302cfc74ded0d93c74fc1292be4
BLAKE2b-256 c0b0fa30a199cae18a8c2eec3dfce3f84e83203ee59c981a1c0f29e59c61e774

See more details on using hashes here.

File details

Details for the file crypto_js_to_py-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for crypto_js_to_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b73c9d9b364e8b4593ab71a2a8b6abacad4dff8e55c1bc58f35c7d2cb20c573d
MD5 d5b19b0700fa1fe423861b3bcc0778a3
BLAKE2b-256 c81b01ae448e78b0218304764379b8e063941eaf46e80f50fd0a9e17e2d0e421

See more details on using hashes here.

Supported by

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