ssh-
1package crypt2
3import (4"crypto/rand"5"ssh+/app/file"6"ssh+/app/output"7
8"github.com/spf13/viper"9)
10
11func getPathToKey() string {12filePath := file.GetFullPath(viper.GetString("NameFileCryptKey"))13
14return filePath15}
16
17func GetKey() []byte {18data, err := file.ReadFile(getPathToKey())19if err != nil {20output.GetOutError("File opening error")21}22
23return []byte(data)24}
25
26func GenerateKey() {27fileName := viper.GetString("NameFileCryptKey")28
29if !file.IsExistFile(fileName) {30file.GenerateFile(fileName)31
32if len(GetKey()) == 0 {33key := make([]byte, 32)34
35_, err := rand.Read(key)36if err != nil {37output.GetOutError("Key generation error")38}39
40file.WriteFile(getPathToKey(), key)41}42}43}
44