putty

package module
v0.0.0-...-dd06a46 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 28 Imported by: 0

README

putty

Go package to parse PuTTY private key formats. Go 1.13 or above is required.

Example

package main

import (
	"log"

	"github.com/liornabat/putty"
)

func main() {
	var privateKey interface{}

	// read the key
	puttyKey, err := putty.NewFromFile("test.ppk")
	if err != nil {
		log.Fatal(err)
	}

	// parse putty key
	if puttyKey.Encryption != "none" {
		// If the key is encrypted, decrypt it
		privateKey, err = puttyKey.ParseRawPrivateKey([]byte("testkey"))
		if err != nil {
			log.Fatal(err)
		}
	} else {
		privateKey, err = puttyKey.ParseRawPrivateKey(nil)
		if err != nil {
			log.Fatal(err)
		}
	}

  // init an empty public key with version 3
  outKey := putty.Key{Version: 3}

  // set the private key
  outKey.SetKey(privateKey)

  // print out the ppk file
  fmt.Printf("%s\n", outKey.Marshal())

	log.Printf("%+#v", privateKey)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key struct {
	Version           int
	Algo              string
	PublicKey         []byte
	PrivateKey        []byte
	KeyDerivation     string
	Argon2Memory      uint32
	Argon2Passes      uint32
	Argon2Parallelism uint8
	Argon2Salt        []byte
	Comment           string
	Encryption        string
	PrivateMac        []byte
	// contains filtered or unexported fields
}

func New

func New(b []byte) (*Key, error)

New creates new PuTTY structure from key bytes

func NewFromFile

func NewFromFile(path string) (*Key, error)

NewFromFile creates new PuTTY structure from file

func (Key) Clone

func (k Key) Clone() *Key

func (*Key) Encrypt

func (k *Key) Encrypt(random io.Reader, password []byte) error

Encrypt encrypts the key and updates the HMAC

func (*Key) Load

func (k *Key) Load(b []byte) error

Load loads PuTTY key bytes into the struct

func (*Key) LoadFromFile

func (k *Key) LoadFromFile(path string) error

LoadFromFile reads PuTTY key and loads its contents into the struct

func (*Key) LoadSSH1

func (k *Key) LoadSSH1(b []byte) error

func (*Key) LoadSSH1WithPassword

func (k *Key) LoadSSH1WithPassword(b []byte, password string) error

func (*Key) Marshal

func (k *Key) Marshal() (ret []byte, err error)

Marshal returns the key in the raw ppk format for saving to a file.

func (*Key) MarshalSSH1

func (k *Key) MarshalSSH1() ([]byte, error)

func (*Key) MarshalSSH1WithPassword

func (k *Key) MarshalSSH1WithPassword(password string) ([]byte, error)

func (*Key) ParseRawPrivateKey

func (k *Key) ParseRawPrivateKey(password []byte) (ret interface{}, err error)

ParseRawPrivateKey returns a private key from a PuTTY encoded private key. It supports RSA (PKCS#1), DSA (OpenSSL), ECDSA and ED25519 private keys.

func (*Key) ParseRawPublicKey

func (k *Key) ParseRawPublicKey() (interface{}, error)

ParseRawPublicKey returns a public key from a PuTTY encoded private key. It supports the same key types as ParseRawPrivateKey, and will work even if the private part is encrypted

func (*Key) SetKey

func (k *Key) SetKey(key interface{}) (err error)

SetPrivateKey sets the private key. It supports RSA (PKCS#1), DSA (OpenSSL), ECDSA and ED25519 private keys.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL