gmessages/libgm/crypto/generate.go

16 lines
237 B
Go
Raw Normal View History

2023-06-30 09:54:08 +00:00
package crypto
import (
"crypto/rand"
2023-07-16 11:36:13 +00:00
"fmt"
2023-06-30 09:54:08 +00:00
)
2023-07-16 11:36:13 +00:00
func GenerateKey(length int) []byte {
2023-06-30 09:54:08 +00:00
key := make([]byte, length)
_, err := rand.Read(key)
if err != nil {
2023-07-16 11:36:13 +00:00
panic(fmt.Errorf("failed to read random bytes: %w", err))
2023-06-30 09:54:08 +00:00
}
2023-07-16 11:36:13 +00:00
return key
2023-06-30 09:55:49 +00:00
}