0
我需要使用Python对输入文本进行加密和解密,但在这里出现以下错误。使用Python调用类方法时发生错误
Traceback (most recent call last):
File "crypto.py", line 21, in <module>
encrypt = AESCipher()
TypeError: __init__() takes exactly 2 arguments (1 given)
我在下面解释我的代码。
import base64
from Crypto.Cipher import AES
from Crypto import Random
class AESCipher:
def __init__(self, thecarkey):
self.key = key
def encrypt(self, raw):
raw = pad(raw)
iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return base64.b64encode(iv + cipher.encrypt(raw))
def decrypt(self, enc):
enc = base64.b64decode(enc)
iv = enc[:16]
cipher = AES.new(self.key, AES.MODE_CBC, iv)
return unpad(cipher.decrypt(enc[16:]))
encrypt = AESCipher()
passw = encrypt.encrypt('[email protected]')
print(passw)
在这里,我需要用类中定义的Crypto.Cipher
但得到上述错误的文本进行加密。
觉得这样的错误信息已经足够明显来解决这个问题。你怎么能写上面的代码,而不能解决问题? –