當前位置: 首頁>>代碼示例>>Golang>>正文


Golang ssh.NewPublicKey函數代碼示例

本文整理匯總了Golang中code/google/com/p/go/crypto/ssh.NewPublicKey函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewPublicKey函數的具體用法?Golang NewPublicKey怎麽用?Golang NewPublicKey使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewPublicKey函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Key

// Key method for ssh.ClientKeyring interface
func (k *SimpleKeychain) Key(i int) (ssh.PublicKey, error) {
	if i < 0 || i >= len(k.keys) {
		return nil, nil
	}
	switch key := k.keys[i].(type) {
	case *rsa.PrivateKey:
		return ssh.NewPublicKey(&key.PublicKey)
	case *dsa.PrivateKey:
		return ssh.NewPublicKey(&key.PublicKey)
	}
	panic("unknown key type")
}
開發者ID:EdevMosaic,項目名稱:packer,代碼行數:13,代碼來源:keychain.go

示例2: Key

func (k *Keychain) Key(i int) (key ssh.PublicKey, err error) {
	if i < 0 || i >= len(k.keys) {
		return nil, nil
	}

	switch key := k.keys[i].(type) {
	case *rsa.PrivateKey:
		return ssh.NewPublicKey(&key.PublicKey)
	case *dsa.PrivateKey:
		return ssh.NewPublicKey(&key.PublicKey)
	}

	return nil, errors.New("ssh: Unknown key type")
}
開發者ID:jaypalominodb,項目名稱:trousseau,代碼行數:14,代碼來源:keychain.go

示例3: CreateSSHKey

// CreateSSHKey is used to generate rsa private & public keys that are used to
// set keys for ssh login to a server.
func CreateSSHKey() (string, string, error) {

	pk, e := rsa.GenerateKey(rand.Reader, 2014)
	if e != nil {
		return "", "", e
	}

	pkDer := x509.MarshalPKCS1PrivateKey(pk)
	pkBlk := pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   pkDer,
	}
	pkPem := string(pem.EncodeToMemory(&pkBlk))

	pubK := pk.PublicKey

	pub, e := ssh.NewPublicKey(&pubK)
	if e != nil {
		return "", "", e
	}

	pubBytes := ssh.MarshalAuthorizedKey(pub)

	return string(pkPem), string(pubBytes), nil
}
開發者ID:rupakg,項目名稱:kube-cluster-deploy,代碼行數:28,代碼來源:sshKey.go

示例4: Run

// Run executes the Packer build step that generates SSH key pairs.
func (s *StepCreateSSHKey) Run(state multistep.StateBag) multistep.StepAction {
	ui := state.Get("ui").(packer.Ui)

	ui.Say("Creating temporary SSH key for instance...")
	priv, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		err := fmt.Errorf("Error creating temporary ssh key: %s", err)
		state.Put("error", err)
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	priv_blk := pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   x509.MarshalPKCS1PrivateKey(priv),
	}

	pub, err := ssh.NewPublicKey(&priv.PublicKey)
	if err != nil {
		err := fmt.Errorf("Error creating temporary ssh key: %s", err)
		state.Put("error", err)
		ui.Error(err.Error())
		return multistep.ActionHalt
	}

	state.Put("ssh_private_key", string(pem.EncodeToMemory(&priv_blk)))
	state.Put("ssh_public_key", string(ssh.MarshalAuthorizedKey(pub)))
	return multistep.ActionContinue
}
開發者ID:EdevMosaic,項目名稱:packer,代碼行數:31,代碼來源:step_create_ssh_key.go

示例5: rsaPubkeyToSSHPubkey

func rsaPubkeyToSSHPubkey(rsakey rsa.PublicKey) (sshkey ssh.PublicKey, err error) {
	sshkey, err = ssh.NewPublicKey(&rsakey)
	if err != nil {
		return nil, err
	}
	return sshkey, nil
}
開發者ID:realestate-com-au,項目名稱:credulous,代碼行數:7,代碼來源:crypto.go

示例6: main

func main() {
	log.SetFlags(0)
	maybePrintInfo()
	maybeProxy()
	args := os.Args[1:]
	runxURL, err := getToken()
	if err != nil {
		log.Fatal(err)
	}
	if len(args) > 0 && args[0] == "-d" {
		args = args[1:]
		_, err := herokuRun(strings.Join(args, " "), nil)
		if err != nil {
			log.Fatal(err)
		}
		return
	}
	key, err := rsa.GenerateKey(rand.Reader, 1024)
	if err != nil {
		log.Fatal("keygen", err)
	}
	pub, err := ssh.NewPublicKey(&key.PublicKey)
	if err != nil {
		log.Fatal(err)
	}
	uuid, err := herokuRun(script, map[string]string{
		"RUNX_URL":        runxURL,
		"AUTHORIZED_KEYS": string(ssh.MarshalAuthorizedKey(pub)),
	})
	if err != nil {
		log.Fatal(err)
	}
	log.Fatal(execSSH(runxURL, uuid, key, args))
}
開發者ID:kr,項目名稱:runx,代碼行數:34,代碼來源:main.go

示例7: TestSSHD

func TestSSHD(t *testing.T) {
	block, _ := pem.Decode([]byte(testClientPrivateKey))
	rsakey, _ := x509.ParsePKCS1PrivateKey(block.Bytes)
	pub, _ := ssh.NewPublicKey(&rsakey.PublicKey)
	cmd, c, err := startSSHD(ssh.MarshalAuthorizedKey(pub))
	if err != nil {
		t.Fatal(err)
	}
	defer cmd.Wait()
	defer cmd.Process.Kill()
	u, err := user.Current()
	if err != nil {
		t.Fatal(err)
	}
	_ = u
	config := &ssh.ClientConfig{
		User: u.Username,
		Auth: []ssh.ClientAuth{ssh.ClientAuthKeyring(&keyring{rsakey})},
	}
	client, err := ssh.Client(c, config)
	if err != nil {
		t.Fatal(err)
	}
	sess, err := client.NewSession()
	if err != nil {
		t.Fatal(err)
	}
	out, err := sess.Output("echo hello")
	if err != nil {
		t.Fatal(err)
	}
	if string(out) != "hello\n" {
		t.Fatalf("out = %q want %q", string(out), "hello\n")
	}
}
開發者ID:kr,項目名稱:runx,代碼行數:35,代碼來源:ssh_test.go

示例8: GenerateKey

func GenerateKey() (pkPem []byte, pubkPem []byte, pubSSHAK []byte, err error) {
	pk, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		return
	}
	pkDer := x509.MarshalPKCS1PrivateKey(pk)
	pkBlock := pem.Block{
		Type:    "RSA PRIVATE KEY",
		Headers: nil,
		Bytes:   pkDer,
	}
	pkPem = pem.EncodeToMemory(&pkBlock)

	pubk := pk.PublicKey
	pubkDer, err := x509.MarshalPKIXPublicKey(&pubk)
	if err != nil {
		return
	}

	pubkBlock := pem.Block{
		Type:    "PUBLIC KEY",
		Headers: nil,
		Bytes:   pubkDer,
	}
	pubkPem = pem.EncodeToMemory(&pubkBlock)

	pubSSH, err := ssh.NewPublicKey(&pubk)
	if err != nil {
		return
	}
	pubSSHAK = ssh.MarshalAuthorizedKey(pubSSH)

	return
}
開發者ID:41px,項目名稱:dmz,代碼行數:34,代碼來源:rsa.go

示例9: marshalPublicKey

// helper function that marshalls an RSA Public Key to an SSH
// .authorized_keys format
func marshalPublicKey(pubkey *rsa.PublicKey) string {
	pk, err := ssh.NewPublicKey(pubkey)
	if err != nil {
		return ""
	}

	return string(ssh.MarshalAuthorizedKey(pk))
}
開發者ID:Jyggafey,項目名稱:drone,代碼行數:10,代碼來源:util.go

示例10: MarshalPublicKey

// helper function that marshalls an RSA Public Key to an SSH
// .authorized_keys format
func MarshalPublicKey(public *rsa.PublicKey) []byte {
	private, err := ssh.NewPublicKey(public)
	if err != nil {
		return []byte{}
	}

	return ssh.MarshalAuthorizedKey(private)
}
開發者ID:fclairamb,項目名稱:drone,代碼行數:10,代碼來源:crypto.go

示例11: marshalKey

// marshalKey returns two byte slices: one represent the private key in the PEM
// format, and the other representing the public key in the authorized_keys
// format.
func marshalKey(keyPair *rsa.PrivateKey) (privateKey []byte, publicKey []byte, err error) {
	sshPublicKey, err := ssh.NewPublicKey(&keyPair.PublicKey)
	if err != nil {
		return nil, nil, err
	}
	publicKey = ssh.MarshalAuthorizedKey(sshPublicKey)
	block := pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(keyPair)}
	privateKey = pem.EncodeToMemory(&block)
	return privateKey, publicKey, nil
}
開發者ID:rualatngua,項目名稱:tsuru,代碼行數:13,代碼來源:ssh_key.go

示例12: Key

func (k *keychain) Key(i int) (ssh.PublicKey, error) {
	if i != 0 {
		return nil, nil
	}
	pubkey, err := ssh.NewPublicKey(&k.key.PublicKey)
	if err != nil {
		log.Panic(err)
	}
	return pubkey, nil
}
開發者ID:hermanschaaf,項目名稱:goship,代碼行數:10,代碼來源:goship.go

示例13: Key

func (k *Keychain) Key(i int) (key ssh.PublicKey, err error) {
	if i != 0 {
		return nil, nil
	}

	// Transform the rsa key into an ssh key
	ssh_publickey, _ := ssh.NewPublicKey(k.key.PublicKey)

	return ssh_publickey, nil
}
開發者ID:nMustaki,項目名稱:trousseau,代碼行數:10,代碼來源:scp_storage.go

示例14: TestCreateServerWithKeyPair

func TestCreateServerWithKeyPair(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
	publicKey := privateKey.PublicKey
	pub, err := ssh.NewPublicKey(&publicKey)
	th.AssertNoErr(t, err)
	pubBytes := ssh.MarshalAuthorizedKey(pub)
	pk := string(pubBytes)

	kp, err := keypairs.Create(client, keypairs.CreateOpts{
		Name:      keyName,
		PublicKey: pk,
	}).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created key pair: %s\n", kp)

	choices, err := ComputeChoicesFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)
	t.Logf("Creating server [%s] with key pair.", name)

	serverCreateOpts := servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
	}

	server, err := servers.Create(client, keypairs.CreateOptsExt{
		serverCreateOpts,
		keyName,
	}).Extract()
	th.AssertNoErr(t, err)
	defer servers.Delete(client, server.ID)
	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatalf("Unable to wait for server: %v", err)
	}

	server, err = servers.Get(client, server.ID).Extract()
	t.Logf("Created server: %+v\n", server)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, server.KeyName, keyName)

	t.Logf("Deleting key pair [%s]...", kp.Name)
	err = keypairs.Delete(client, keyName).ExtractErr()
	th.AssertNoErr(t, err)

	t.Logf("Deleting server [%s]...", name)
}
開發者ID:cdosso,項目名稱:machine,代碼行數:55,代碼來源:keypairs_test.go

示例15: GenerateNewPublicKey

func GenerateNewPublicKey() string {
	key, err := rsa.GenerateKey(rand.Reader, 2048)
	if err != nil {
		log.Fatal("Failed to generate new RSA key: ", err)
	}
	pk, err := ssh.NewPublicKey(&key.PublicKey)
	if err != nil {
		log.Fatal("Failed to generate public key: ", err)
	}
	return string(ssh.MarshalAuthorizedKey(pk))
}
開發者ID:reinbach,項目名稱:go-stash,代碼行數:11,代碼來源:keys_test.go


注:本文中的code/google/com/p/go/crypto/ssh.NewPublicKey函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。