跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 有无大佬帮忙把这段 Python 代码转换成 JavaScript
未分類
27 2 月 2021

有无大佬帮忙把这段 Python 代码转换成 JavaScript

有无大佬帮忙把这段 Python 代码转换成 JavaScript

資深大佬 : Janxun 3

代码如下,非常感觉!

import base64 from Crypto.Cipher import AES  class Encrypt(object):     def __init__(self):         self.key = "ABCDEXGH01234567".encode("utf8")         self.length = AES.block_size         self.aes = AES.new(self.key, AES.MODE_ECB)      def pad(self, text):         count = len(text.encode('utf-8'))         add = self.length - (count % self.length)         return text + (chr(add) * add)      def encrypt(self, encrData):         res = self.aes.encrypt(self.pad(encrData).encode("utf8"))         msg = str(base64.b64encode(res), encoding="utf8")         return msg  if __name__ == '__main__':     e = Encrypt()     a = e.encrypt("12345678")     print(a) 

大佬有話說 (10)

  • 資深大佬 : tulongtou

    你的工作为啥想让别人免费给你做

  • 資深大佬 : kaikai5601

    你的工作为啥想让别人免费给你做

  • 資深大佬 : FaiChou

    代码如下,非常感觉!

  • 資深大佬 : kingfalse

    一个简单的加密.自己百度一下就能搞定

  • 資深大佬 : SilverLink

    解一个 AES 加密,还原 base64 编码

  • 主 資深大佬 : Janxun

    @kingfalse 好吧,我再试试

  • 資深大佬 : darksword21

    console.log(“import base64
    from Crypto.Cipher import AES

    class Encrypt(object):
    def __init__(self):
    self.key = “ABCDEXGH01234567”.encode(“utf8”)
    self.length = AES.block_size
    self.aes = AES.new(self.key, AES.MODE_ECB)

    def pad(self, text):
    count = len(text.encode(‘utf-8’))
    add = self.length – (count % self.length)
    return text + (chr(add) * add)

    def encrypt(self, encrData):
    res = self.aes.encrypt(self.pad(encrData).encode(“utf8”))
    msg = str(base64.b64encode(res), encoding=”utf8″)
    return msg

    if __name__ == ‘__main__’:
    e = Encrypt()
    a = e.encrypt(“12345678”)
    print(a)”)

  • 主 資深大佬 : Janxun

    “`javascript
    const CryptoJS = require(‘crypto-js’);

    function cryptoEncrypt(word) {
    const key = CryptoJS.enc.Utf8.parse(“ABCDEXGH01234567”);
    const encrypted = CryptoJS.AES.encrypt(word, key, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
    })
    return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
    }
    “`

  • 資深大佬 : solopython

    人家就是问个技术问题,#1#2 你们可以选择不回答,没必要还挖苦人家,我看国外的技术论坛从来就没有像你们这样的人,悲哀

  • 資深大佬 : acmore

    @solopython 问技术问题的方法是:用 JS 的什么库可以完成 AES 加密,或者顶多再问下 Padding 的细节,而不是 “我有段代码不会翻译,师爷你给翻译翻译什么叫 AES”。后者在国外也会被群嘲的。

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具