小编Loo*_*per的帖子

在 Go 中解密在 Python 中以 CFB 模式使用 AES 加密的内容

问题

\n

我希望能够在 Go 中解密在 Python 中加密的内容。加密/解密函数分别在每种语言中工作,但当我在 Python 中加密并在 Go 中解密时则不然,我猜测编码有问题,因为我得到了乱码输出:

\n
Rx\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdd\xef\xbf\xbd\xef\xbf\xbdI\xef\xbf\xbdK|\xef\xbf\xbdap\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdk\xef\xbf\xbd\xef\xbf\xbdB%F\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdUV\xef\xbf\xbd~d3h\xef\xbf\xbd\xc3\x91\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd|\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd>\xef\xbf\xbdB\xef\xbf\xbd\xef\xbf\xbdB\xef\xbf\xbd\n
Run Code Online (Sandbox Code Playgroud)\n

Python 中的加密/解密

\n
def encrypt(plaintext, key=config.SECRET, key_salt='', no_iv=False):\n    """Encrypt shit the right way"""\n\n    # sanitize inputs\n    key = SHA256.new((key + key_salt).encode()).digest()\n    if len(key) not in AES.key_size:\n        raise Exception()\n    if isinstance(plaintext, string_types):\n        plaintext = plaintext.encode('utf-8')\n\n    # pad plaintext using PKCS7 padding scheme\n    padlen = AES.block_size - len(plaintext) % AES.block_size\n    plaintext += (chr(padlen) * padlen).encode('utf-8')\n\n    # generate random initialization vector using CSPRNG\n    if no_iv:\n        iv = ('\\0' * …
Run Code Online (Sandbox Code Playgroud)

python encryption encoding aes go

4
推荐指数
1
解决办法
1214
查看次数

标签 统计

aes ×1

encoding ×1

encryption ×1

go ×1

python ×1