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.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

crypto_js_to_py-0.2.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: crypto-js-to-py-0.2.0.tar.gz
  • Upload date:
  • Size: 8.7 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.0.tar.gz
Algorithm Hash digest
SHA256 d0b8541de1637a40c6527f01abdeedd67171081e2959f9c59a8af7461cbcb586
MD5 44b985532ecf85b5278ec865504cdf32
BLAKE2b-256 01a6041a554451c3e072127095f10a0a8823765ae3078d16ec23b6d0411b07ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for crypto_js_to_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5baf1ec4980c94ab075fe724c51afa074aaf820b5d086ba4cf0826aafdcc3f61
MD5 31b67ad8de0ea53cde8c19dd3056af40
BLAKE2b-256 4ca1bb8e2dfe6e5ba146f94ce72790fb86e297f985e05cd16df69c62b06ab20d

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