我试图加密IOS中的字符串,然后将其发送到TCP服务器.Python版本的代码和iOS版本如下所示.请查看两个版本的输出.它们看起来非常相似,但长度不同,我不知道原因.任何人都可以检查一下,可能是什么原因?
请注意,Python脚本中的PADDING应该被丢弃,因为我已经给出了16的文本长度.
PYTHON代码:
#!/usr/bin/env python
from Crypto.Cipher import AES
import base64
import os
# the block size for the cipher object; must be 16, 24, or 32 for AES
BLOCK_SIZE = 16
PADDING = '{'
# one-liner to sufficiently pad the text to be encrypted
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
# one-liners to encrypt/encode and decrypt/decode a string
# encrypt with AES, encode with base64
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
DecodeAES …Run Code Online (Sandbox Code Playgroud)