python的AES解密CBC模式怎么移植到golang啊。挠头

jayesslin · · 2239 次点击
golang 对应的搞定: ``` func AesCBCDncrypt(encryptData, key []byte) ([]byte,error) { block, err := aes.NewCipher(key) if err != nil { panic(err) } blockSize := kIvSize if len(encryptData) < blockSize { panic("ciphertext too short") } //iv := encryptData[:blockSize] iv := encryptData[:kIvSize] encryptData = encryptData[blockSize:len(encryptData)-kHashSize] // CBC mode always works in whole blocks. if len(encryptData)%blockSize != 0 { panic("ciphertext is not a multiple of the block size") } mode := cipher.NewCBCDecrypter(block, iv) // CryptBlocks can work in-place if the two arguments are the same. mode.CryptBlocks(encryptData, encryptData) //解填充 encryptData = PKCS7UnPadding(encryptData) return encryptData,nil } func PKCS7UnPadding(origData []byte) []byte { length := len(origData) unpadding := int(origData[length-1]) return origData[:(length - unpadding)] } ```
#2
更多评论
aes 是分组密码,一个block相当于一个组
#1