Skip to content

Instantly share code, notes, and snippets.

@bulatie
Created May 14, 2019 03:22
Show Gist options
  • Save bulatie/9788995af1d931ac81135636bf271c78 to your computer and use it in GitHub Desktop.
Save bulatie/9788995af1d931ac81135636bf271c78 to your computer and use it in GitHub Desktop.
encode from go, decode in python by using aes cfb
SEGMENT_SIZE=128
BLOCK_SIZE = 16
cipher = AES.new(KEY, AES.MODE_CFB, IV, segment_size=SEGMENT_SIZE)
dc = dynamic_token.decode("hex")
pt = cipher.decrypt(dc)
print pt
func padString(data []byte) []byte {
padNum := len(data) % 16
if padNum != 0 {
for i := 0; i < 16-padNum; i++ {
data = append(data, ',')
}
}
return data
}
func encodeCipherText(text string) string {
paddedText := padString([]byte(text))
c, err := aes.NewCipher([]byte(SECRET_KEY))
if err != nil {
fmt.Println(418)
}
cfb := cipher.NewCFBEncrypter(c, IV)
ciphertext := make([]byte, len(paddedText))
cfb.XORKeyStream(ciphertext, paddedText)
fmt.Println(ciphertext)
return hex.EncodeToString(ciphertext[:])
}

ref1 ref2

python system uses CFB8 (8 bit segments). Go does not support this out of the box.

good for me link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment