ssh

package
v1.0.1028 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SSHAES128CTR = "aes128-ctr"
	SSHAES192CTR = "aes192-ctr"
	SSHAES256CTR = "aes256-ctr"

	SSHAES128CBC = "aes128-cbc"
	SSHAES192CBC = "aes192-cbc"
	SSHAES256CBC = "aes256-cbc"
)
View Source
var AES128CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES128CBC is the 128-bit key AES cipher in CBC mode.

View Source
var AES128CTR = CipherCTR{
	// contains filtered or unexported fields
}

AES128CTR is the 128-bit key AES cipher in CTR mode.

View Source
var AES192CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES192CBC is the 192-bit key AES cipher in CBC mode.

View Source
var AES192CTR = CipherCTR{
	// contains filtered or unexported fields
}

AES192CTR is the 192-bit key AES cipher in CTR mode.

View Source
var AES256CBC = CipherCBC{
	// contains filtered or unexported fields
}

AES256CBC is the 256-bit key AES cipher in CBC mode.

View Source
var AES256CTR = CipherCTR{
	// contains filtered or unexported fields
}

AES256CTR is the 256-bit key AES cipher in CTR mode.

View Source
var DefaultOptions = Options{
	Cipher: AES256CTR,
	KDFOpts: BcryptOpts{
		SaltSize: 16,
		Rounds:   16,
	},
	Comment: "ssh",
}

默认配置

Functions

func AddCipher

func AddCipher(name string, cipher func() Cipher)

添加加密

func AddKDF

func AddKDF(name string, params func() KDFParameters)

添加 kdf 方式

func AddKey

func AddKey(name string, key func() Key)

添加Key

func GetStructName

func GetStructName(name any) string

反射获取结构体名称

func MarshalOpenSSHPrivateKey

func MarshalOpenSSHPrivateKey(key crypto.PrivateKey, password string, opts ...Options) (*pem.Block, error)

编码

func ParseOpenSSHPrivateKey

func ParseOpenSSHPrivateKey(key []byte, password string) (crypto.PrivateKey, error)

解析

Types

type BcryptOpts

type BcryptOpts struct {
	SaltSize int
	Rounds   int
}

BcryptOpts 设置

func (BcryptOpts) DeriveKey

func (this BcryptOpts) DeriveKey(password []byte, size int) (key []byte, params string, err error)

func (BcryptOpts) GetSaltSize

func (this BcryptOpts) GetSaltSize() int

func (BcryptOpts) Name

func (this BcryptOpts) Name() string

type Cipher

type Cipher interface {
	// 名称
	Name() string

	// 值大小
	KeySize() int

	// 块大小
	BlockSize() int

	// 加密, 返回: [加密后数据, error]
	Encrypt(key, plaintext []byte) ([]byte, error)

	// 解密
	Decrypt(key, ciphertext []byte) ([]byte, error)
}

加密接口

func ParseCipher

func ParseCipher(cipherName string) (Cipher, error)

type CipherCBC

type CipherCBC struct {
	// contains filtered or unexported fields
}

cbc 模式加密

func (CipherCBC) BlockSize

func (this CipherCBC) BlockSize() int

块大小

func (CipherCBC) Decrypt

func (this CipherCBC) Decrypt(key, ciphertext []byte) ([]byte, error)

解密

func (CipherCBC) Encrypt

func (this CipherCBC) Encrypt(key, plaintext []byte) ([]byte, error)

加密

func (CipherCBC) KeySize

func (this CipherCBC) KeySize() int

值大小

func (CipherCBC) Name

func (this CipherCBC) Name() string

oid

type CipherCTR

type CipherCTR struct {
	// contains filtered or unexported fields
}

CTR 模式加密

func (CipherCTR) BlockSize

func (this CipherCTR) BlockSize() int

块大小

func (CipherCTR) Decrypt

func (this CipherCTR) Decrypt(key, ciphertext []byte) ([]byte, error)

解密

func (CipherCTR) Encrypt

func (this CipherCTR) Encrypt(key, plaintext []byte) ([]byte, error)

加密

func (CipherCTR) KeySize

func (this CipherCTR) KeySize() int

值大小

func (CipherCTR) Name

func (this CipherCTR) Name() string

名称

type KDFOpts

type KDFOpts interface {
	// 名称
	Name() string

	// 生成密钥
	DeriveKey(password []byte, size int) (key []byte, params string, err error)

	// 随机数大小
	GetSaltSize() int
}

KDF 设置接口

type KDFParameters

type KDFParameters interface {
	// 生成密钥
	DeriveKey(password []byte, kdfOpts string, size int) (key []byte, err error)
}

数据接口

func ParsePbkdf

func ParsePbkdf(kdfName string) (KDFParameters, error)

type Key

type Key interface {
	// 包装
	Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error)

	// 解析
	Parse(data []byte) (crypto.PrivateKey, error)
}

Key 接口

func ParseKeytype

func ParseKeytype(keytype string) (Key, error)

type KeyEcdsa

type KeyEcdsa struct{}

ecdsa

func (KeyEcdsa) Marshal

func (this KeyEcdsa) Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error)

包装

func (KeyEcdsa) Parse

func (this KeyEcdsa) Parse(rest []byte) (crypto.PrivateKey, error)

包装

type KeyEdDsa

type KeyEdDsa struct{}

EdDsa

func (KeyEdDsa) Marshal

func (this KeyEdDsa) Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error)

包装

func (KeyEdDsa) Parse

func (this KeyEdDsa) Parse(rest []byte) (crypto.PrivateKey, error)

包装

type KeyRsa

type KeyRsa struct{}

rsa

func (KeyRsa) Marshal

func (this KeyRsa) Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error)

包装

func (KeyRsa) Parse

func (this KeyRsa) Parse(rest []byte) (crypto.PrivateKey, error)

包装

type Options

type Options struct {
	Cipher  Cipher
	KDFOpts KDFOpts
	Comment string
}

配置

Jump to

Keyboard shortcuts

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