I know using openssl (tested with OpenSSL 1.1.0g), the following stanza works to decrypt enc.ts, mimetype: video/MP2T, to a ffplay
playable clear.ts h264 segment:
openssl aes-128-cbc -d -in enc.ts -out clear.ts -iv 353833383634 -K 9e8c69bcaafa6b636e076935e29986b5 -nosalt
Though with Golang's https://golang.org/pkg/crypto/cipher/#NewCBCDecrypter I'm very confused how the hexadecimal key and iv are set as byte slices, whether block sizes are a factor and how to load and write out the file.
I have tried:
package main
import (
"crypto/aes"
"crypto/cipher"
"encoding/hex"
"fmt"
"io/ioutil"
)
func checkerror(err error) {
if err != nil {
panic(err)
}
}
func main() {
key, err := hex.DecodeString("9e8c69bcaafa6b636e076935e29986b5")
checkerror(err)
iv, err := hex.DecodeString("353833383634")
checkerror(err)
ciphertext, err := ioutil.ReadFile("enc.ts")
checkerror(err)
block, err := aes.NewCipher(key)
checkerror(err)
mode := cipher.NewCBCDecrypter(block, iv)
mode.CryptBlocks(ciphertext, ciphertext)
fmt.Printf("%s
", ciphertext)
}
But that results in a panic: cipher.NewCBCDecrypter: IV length must equal block size
. What am I missing?