python 代码如下:
```
def decrypt_netlog(raw_data):
base64_decoded_data = base64.b64decode(raw_data)
if len(base64_decoded_data) < kIvSize * 2 + kHashSize:
raise DecryptError('Invalid data length.')
if not hmac.compare_digest(hmac.new(hmac_key, base64_decoded_data[:-kHashSize], hashlib.sha256).digest(),
base64_decoded_data[-kHashSize:]):
raise DecryptError('HMAC checking failed.')
iv = base64_decoded_data[:kIvSize]
cipher = AES.new(encryption_key, AES.MODE_CBC, iv)
text = cipher.decrypt(base64_decoded_data[kIvSize:-kHashSize])
return zlib.decompress(text, 16 + zlib.MAX_WBITS)
```
golang 里AES 的block概念是个啥呀。。。。
更多评论
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