代码如下,非常感觉!
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)
已完成,大家费心了!
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);
}
1
tulongtou 2021-03-04 18:38:57 +08:00 via iPhone
你的工作为啥想让别人免费给你做
|
2
kaikai5601 2021-03-04 18:42:20 +08:00
你的工作为啥想让别人免费给你做
|
3
FaiChou 2021-03-04 18:42:53 +08:00
代码如下,非常感觉!
|
4
kingfalse 2021-03-04 18:45:34 +08:00
一个简单的加密.自己百度一下就能搞定
|
5
SilverLink 2021-03-04 18:49:01 +08:00
解一个 AES 加密,还原 base64 编码
|
7
darksword21 2021-03-04 19:11:11 +08:00 via iPhone
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)”) |
8
Janxun OP ```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); } ``` |
9
solopython 2021-03-05 10:05:40 +08:00
人家就是问个技术问题,#1#2 你们可以选择不回答,没必要还挖苦人家,我看国外的技术论坛从来就没有像你们这样的人,悲哀
|
10
acmore 2021-03-05 10:44:02 +08:00
@solopython 问技术问题的方法是:用 JS 的什么库可以完成 AES 加密,或者顶多再问下 Padding 的细节,而不是 “我有段代码不会翻译,师爷你给翻译翻译什么叫 AES”。后者在国外也会被群嘲的。
|