// GetKey returns a key by ID func (ccs *CryptoService) GetKey(keyID string) data.PublicKey { key, _, err := ccs.keyStore.GetKey(keyID) if err != nil { return nil } return data.PublicKeyFromPrivate(key) }
// Create is used to generate keys for targets, snapshots and timestamps func (ccs *CryptoService) Create(role string, algorithm data.KeyAlgorithm) (data.PublicKey, error) { var privKey data.PrivateKey var err error switch algorithm { case data.RSAKey: privKey, err = trustmanager.GenerateRSAKey(rand.Reader, rsaKeySize) if err != nil { return nil, fmt.Errorf("failed to generate RSA key: %v", err) } case data.ECDSAKey: privKey, err = trustmanager.GenerateECDSAKey(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate EC key: %v", err) } case data.ED25519Key: privKey, err = trustmanager.GenerateED25519Key(rand.Reader) if err != nil { return nil, fmt.Errorf("failed to generate ED25519 key: %v", err) } default: return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm) } logrus.Debugf("generated new %s key for role: %s and keyID: %s", algorithm, role, privKey.ID()) // Store the private key into our keystore with the name being: /GUN/ID.key with an alias of role err = ccs.keyStore.AddKey(filepath.Join(ccs.gun, privKey.ID()), role, privKey) if err != nil { return nil, fmt.Errorf("failed to add key to filestore: %v", err) } return data.PublicKeyFromPrivate(privKey), nil }
func (e *Ed25519) PublicKeys(keyIDs ...string) (map[string]data.PublicKey, error) { k := make(map[string]data.PublicKey) for _, kID := range keyIDs { if key, ok := e.keys[kID]; ok { k[kID] = data.PublicKeyFromPrivate(key) } } return k, nil }
// Create is used to generate keys for targets, snapshots and timestamps func (ccs *CryptoService) Create(role string) (*data.PublicKey, error) { privKey, err := trustmanager.GenerateRSAKey(rand.Reader, rsaKeySize) if err != nil { return nil, fmt.Errorf("failed to generate RSA key: %v", err) } // Store the private key into our keystore with the name being: /GUN/ID.key ccs.keyStore.AddKey(filepath.Join(ccs.gun, privKey.ID()), privKey) return data.PublicKeyFromPrivate(*privKey), nil }
// PublicKey Returns the public key associated with the private key func (ucs *UnlockedCryptoService) PublicKey() *data.PublicKey { return data.PublicKeyFromPrivate(*ucs.PrivKey) }
func (e *Ed25519) GetKey(keyID string) data.PublicKey { return data.PublicKeyFromPrivate(e.keys[keyID]) }
// PublicKey Returns the public key associated with the Private Key within the Signer func (uk *UnlockedSigner) PublicKey() *data.PublicKey { return data.PublicKeyFromPrivate(*uk.privKey) }