I know, using openssl (tested with OpenSSL 1.1.0g), the following stanza works to decrypt enc.ts , mimetype: video / MP2T, into the h264 segment clear.ts h264 ffplay
:
openssl aes-128-cbc -d -in enc.ts -out clear.ts -iv 353833383634 -K 9e8c69bcaafa6b636e076935e29986b5 -nosalt
Although with Golang https://golang.org/pkg/crypto/cipher/#NewCBCDecrypter I am very confused how the hexadecimal key and iv are set as byte fragments, regardless of whether the block sizes are a factor and how to load and write the file.
I 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\n", ciphertext)
}
But this leads to a panic: cipher.NewCBCDecrypter: IV length must equal block size
. What am I missing?
source
share