antonmarin/secret-yaml

View on GitHub
random/crypto.go

Summary

Maintainability
A
0 mins
Test Coverage
C
75%
package random

import (
    "crypto/rand"
    "encoding/hex"
)

type CryptoGeneratorService struct {
}

func (service CryptoGeneratorService) GenerateSecretKey() ([]byte, error) {
    randomBytes := make([]byte, 16)
    if _, err := rand.Read(randomBytes); err != nil {
        return nil, err
    }

    result := []byte(hex.EncodeToString(randomBytes))

    return result, nil
}