
- СПРИНТ BE 15.09.22-01.10.22 (#2zabn3t) - BE Yandex API common - навесить обработчик ошибок (#2vc86am) Changes: - Удалены эндпоинты и шаблоны страниц, кроме 404 - MiddlewareAmoJwt теперь является основным
61 lines
986 B
Go
61 lines
986 B
Go
package tools
|
|
|
|
import (
|
|
"crypto/rc4"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
)
|
|
|
|
const (
|
|
TokenKey = "z1eRU{fq*VtfLAszrz"
|
|
)
|
|
|
|
type StateToken struct {
|
|
UserID string `json:"user_id"`
|
|
Service string `json:"service"` // yandex, google, etc
|
|
RedirectUrl string `json:"redirect_url"`
|
|
}
|
|
|
|
func EncryptTokenRC4(data any) (string, error) {
|
|
cipher, err := rc4.NewCipher([]byte(TokenKey))
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
msg, err := json.Marshal(data)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
encrypted := make([]byte, len(msg))
|
|
cipher.XORKeyStream(encrypted, msg)
|
|
|
|
return hex.EncodeToString(encrypted), nil
|
|
}
|
|
|
|
func DecryptTokenRC4(data string, result any) error {
|
|
cipher, err := rc4.NewCipher([]byte(TokenKey))
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
msg, err := hex.DecodeString(data)
|
|
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
decrypted := make([]byte, len(msg))
|
|
|
|
cipher.XORKeyStream(decrypted, msg)
|
|
|
|
err = json.Unmarshal(decrypted, &result)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|