0

i have a aes/cfb encrypt of python code that needs to be implemented in golang, the segment_size arg was be set to 8 in python, but I didn't find a method to change segment size in golang

python code like below

from Crypto.Cipher import AES

key = b"0123456789abcdef0123456789abcdef"
iv = b"0123456789abcdef"
data = "123456".encode()

cipher = AES.new(key=key, iv=iv, mode=AES.MODE_CFB, segment_size=8)
cipher_text = cipher.encrypt(data)
# hex cipher_text: c93c1b04ac56

golang code like below

key := []byte("0123456789abcdef0123456789abcdef")
iv := []byte("0123456789abcdef")
data := []byte("123456")
block, _ := aes.NewCipher(key)
stream := cipher.NewCFBEncrypter(block, iv)
cipherText := make([]byte, len(data))
stream.XORKeyStream(cipherText, data)
// hex cipherText: c90ea954e93a

when i set segment_size to 64 in python, the result was result is consistent with golang (c90ea954e93a)

calico
  • 1
  • 1
  • Alternatively to the solutions described in the linked post see https://pkg.go.dev/github.com/Tnze/gomcbot/CFB8 – Topaco Jul 13 '23 at 09:10

0 Answers0