jmc is a Go implementation of the encrypted-config-value library.
go install github.com/zs5460/jmc/cmd/jmc@latest
To modify the profile, the values that need to be encrypted are wrapped in "${enc" and "}"
//config.json
{
"password":"123456"
}
Change to
{
"password":"${enc:123456}"
}
Use the app to encrypt the profile
jmc config.json
You can see that the values in the profile are encrypted
{
"password":"${enc:bPbmRmA8PvGhcby5LEgBuw==}"
}
Refer to the jmc package in the program to call the MustLoadconfig method to load and decrypt the profile
package main
import (
"fmt"
"github.com/zs5460/jmc"
)
func main() {
var cfg map[string]string
jmc.MustLoadConfig("config.json", &cfg)
fmt.Println(cfg["password"])
//output: 123456
}
In a production environment, you should set the environment variable "JMC_K" to change the encryption key
Released under MIT license, see LICENSE for details.