putty

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2021 License: Apache-2.0 Imports: 24 Imported by: 2

README

putty

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

Example

package main

import (
	"log"

	"github.com/kayrus/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)
		}
	}

	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) 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) ParseRawPrivateKey

func (k *Key) ParseRawPrivateKey(password []byte) (interface{}, 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 added in v1.0.2

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

Jump to

Keyboard shortcuts

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