Skip to main content

介绍

这是一个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()

Release files for crypto-js-to-py 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crypto-js-to-py 0.2.2
File Size Uploaded
crypto-js-to-py-0.2.2.tar.gz 9.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crypto-js-to-py 0.2.2
File Interpreter ABI Platform
crypto_js_to_py-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / crypto-js-to-py-0.2.2.tar.gz

Download URL crypto-js-to-py-0.2.2.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
75c69662dcdd5c65f422e5566b363f19bcb0a6ebcce3e8abf27b114fb6b8b1e7
BLAKE2b-256 checksum
How to use checksums
68b9218341e799955d3ec155c4004e1f330630d6a8fd6fcf5d020fcd78a0e3fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / crypto_js_to_py-0.2.2-py3-none-any.whl

Download URL crypto_js_to_py-0.2.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6818ba6fb96de1564cb2c4f1363901ba5800587e977df79f70d21178d855b9fb
BLAKE2b-256 checksum
How to use checksums
d8f130a72febe7716900e4bc400e3d89162228dbcc2bacdf4abd0b2711b3e87f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page