ssh-

Форк
0
/
crypt_key.go 
43 строки · 715.0 Байт
1
package crypt
2

3
import (
4
	"crypto/rand"
5
	"ssh+/app/file"
6
	"ssh+/app/output"
7

8
	"github.com/spf13/viper"
9
)
10

11
func getPathToKey() string {
12
	filePath := file.GetFullPath(viper.GetString("NameFileCryptKey"))
13

14
	return filePath
15
}
16

17
func GetKey() []byte {
18
	data, err := file.ReadFile(getPathToKey())
19
	if err != nil {
20
		output.GetOutError("File opening error")
21
	}
22

23
	return []byte(data)
24
}
25

26
func GenerateKey() {
27
	fileName := viper.GetString("NameFileCryptKey")
28

29
	if !file.IsExistFile(fileName) {
30
		file.GenerateFile(fileName)
31

32
		if len(GetKey()) == 0 {
33
			key := make([]byte, 32)
34

35
			_, err := rand.Read(key)
36
			if err != nil {
37
				output.GetOutError("Key generation error")
38
			}
39

40
			file.WriteFile(getPathToKey(), key)
41
		}
42
	}
43
}
44

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.