MCPcopy
hub / github.com/determined-ai/determined / generateRSAKey

Function generateRSAKey

master/pkg/ssh/ssh.go:44–68  ·  view source on GitHub ↗
(rsaKeySize int)

Source from the content-addressed store, hash-verified

42}
43
44func generateRSAKey(rsaKeySize int) (PrivateAndPublicKeys, error) {
45 privateKey, err := rsa.GenerateKey(rand.Reader, rsaKeySize)
46 if err != nil {
47 return PrivateAndPublicKeys{}, errors.Wrap(err, "unable to generate RSA private key")
48 }
49
50 if err = privateKey.Validate(); err != nil {
51 return PrivateAndPublicKeys{}, err
52 }
53
54 block := &pem.Block{
55 Type: rsaPEMBlockType,
56 Bytes: x509.MarshalPKCS1PrivateKey(privateKey),
57 }
58
59 publicKey, err := sshlib.NewPublicKey(&privateKey.PublicKey)
60 if err != nil {
61 return PrivateAndPublicKeys{}, errors.Wrap(err, "unable to generate RSA public key")
62 }
63
64 return PrivateAndPublicKeys{
65 PrivateKey: pem.EncodeToMemory(block),
66 PublicKey: sshlib.MarshalAuthorizedKey(publicKey),
67 }, nil
68}
69
70func generateECDSAKey() (PrivateAndPublicKeys, error) {
71 // Curve size currently not configurable, using the NIST recommendation.

Callers 1

GenerateKeyFunction · 0.85

Calls 1

ValidateMethod · 0.65

Tested by

no test coverage detected