func DecodeFts(cipherpath, ftspath, password string) (err error) {
if len(password) != 7 {
return
}
log.Println(ftspath, filepath.Dir(ftspath), filepath.Base(ftspath))
os.Chdir(filepath.Dir(ftspath))
cmd := exec.Command(cipherpath, filepath.Base(ftspath))
inr, inw := io.Pipe()
outr, outw := io.Pipe()
cmd.Stdin = inr
cmd.Stdout = outw
if err = cmd.Start(); err != nil {
return
}
go cmd.Wait()
strs := []string{
"PRAGMA key = '" + password + "';",
"PRAGMA cipher = 'aes-256-cbc';",
"PRAGMA cipher_use_hmac = ON;",
"PRAGMA cipher_page_size = 4096;",
"PRAGMA kdf_iter = 64000;",
".backup fts_de.db",
".q",
}
for _, str := range strs {
_, err = encode(bufio.NewReader(outr), inw, str)
if err != nil {
log.Println(err.Error())
return err
}
}
return
}
func encode(r *bufio.Reader, w io.Writer, str string) (string, error) {
n, err := w.Write([]byte(str))
if err != nil {
log.Println(n, err.Error())
return "", err
}
n, err = w.Write([]byte("\n"))
if err != nil {
log.Println(n, err.Error())
return "", err
}
return "", err
}
有疑问加站长微信联系(非本文作者)