首页 > 解决方案 > 如何解密使用 Openssl aes-256-cbc 加密的 Go 文件

问题描述

我正在使用 OpenSSL AES-256-CBC 加密我的一些文件

openssl aes-256-cbc -in filename.txt -out filename.enc -k password

如何在 Go 中解密这些文件?

标签: goencryptionopensslaes

解决方案


我希望这会有所帮助,请确保您在opensslEncrypted变量中读取文件字节:

安装

git clone https://github.com/funny/crypto

解密:

import (
  "fmt"
  "github.com/funny/crypto/aes256cbc"
)

func main() {
    opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU="
    passphrase := "z4yH36a6zerhfE5427ZV"

    dec, err := aes256cbc.DecryptString(passphrase, opensslEncrypted)
    if err != nil {
        fmt.Printf("An error occurred: %s\n", err)
    }

    fmt.Printf("Decrypted text: %s\n", string(dec))
}

来源:github


推荐阅读