我尝试实现之间的通信
在python 服务器端iv
,我使用 an和 a加密一个字符串,passphrase
并将带有加密文本 base64 编码的 iv 发送到javascript 客户端。然后我想要decrypt
用户可以输入的带有密码的字符串。
蟒蛇 - 服务器
from Crypto.Cipher import AES
from Crypto import Random
iv = Random.get_random_bytes(16)
key = "1234567812345678"
aes = AES.new(key, AES.MODE_CFB, iv)
encrypted_text = base64.b64encode(aes.encrypt("this is a test.."))
iv = base64.b64encode(iv)
# send iv, encrypted_text to client
javascript - 客户端
// <script type="text/javascript"
src="http://crypto-js.googlecode.com/files/2.5.3-crypto-sha1-hmac-pbkdf2-blockmodes-aes.js">
</script>
// text, and iv is base64encoded from the python script
// key is a string from an <input type='text'>
decrypted = Crypto.AES.decrypt(text, key, {iv: iv, mode: new Crypto.mode.CFB});
在这个例子中,我得到一个 javascript 错误
Uncaught URIError: URI malformed
但这只是一个例子——我尝试了所有我能想到的 base64 编码/解码。我也尝试改变模式。但这些都是随机测试,我想了解我真正要做的事情。
- crypt-js 想要什么编码?
- 我应该选择哪种模式?
- python服务器端有什么我应该改变的吗?
- 什么是填充?会不会有错?
- 您可以推荐任何其他 javascript 库吗?
非常感谢和亲切的问候,武士