main.go 747 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "crypto/rand"
  4. "crypto/rsa"
  5. "crypto/x509"
  6. "encoding/pem"
  7. "os"
  8. )
  9. func main() {
  10. keyPair, err := rsa.GenerateKey(rand.Reader, 4096)
  11. if err != nil {
  12. panic(err)
  13. }
  14. // encrypt as pem
  15. newPrivateKey := x509.MarshalPKCS1PrivateKey(keyPair)
  16. newPublicKey := x509.MarshalPKCS1PublicKey(&keyPair.PublicKey)
  17. if err != nil {
  18. panic(err)
  19. }
  20. privateKeyPem := pem.EncodeToMemory(&pem.Block{
  21. Type: "RSA PRIVATE KEY",
  22. Bytes: newPrivateKey,
  23. })
  24. publicKeyPem := pem.EncodeToMemory(&pem.Block{
  25. Type: "RSA PUBLIC KEY",
  26. Bytes: newPublicKey,
  27. })
  28. os.WriteFile("internal/core/license/private_key/PRIVATE_KEY.pem", privateKeyPem, 0644)
  29. os.WriteFile("internal/core/license/public_key/PUBLIC_KEY.pem", publicKeyPem, 0644)
  30. }