Documentation ¶
Index ¶
- Variables
- func AddCipher(name string, cipher func() Cipher)
- func AddKDF(name string, params func() KDFParameters)
- func AddKey(name string, key func() Key)
- func AddPubKeyParser(name string, parser PubKeyParser)
- func EncodeSSHKeyToPem(keyBlock *pem.Block) []byte
- func GetStructName(s any) (name string)
- func MarshalAuthorizedKey(key ssh.PublicKey) []byte
- func MarshalAuthorizedKeyWithComment(key ssh.PublicKey, comment string) []byte
- func MarshalOpenSSHPrivateKey(rand io.Reader, key crypto.PrivateKey, comment string) (*pem.Block, error)
- func MarshalOpenSSHPrivateKeyWithPassword(rand io.Reader, key crypto.PrivateKey, comment string, password []byte, ...) (*pem.Block, error)
- func NewPublicKey(key any) (out ssh.PublicKey, err error)
- func NewSM2PrivateKey(key *sm2.PrivateKey) ssh.Signer
- func NewSM2PublicKey(key *sm2.PublicKey) ssh.PublicKey
- func NewSignerFromKey(key any) (out ssh.Signer, err error)
- func ParseAuthorizedKey(in []byte) (out ssh.PublicKey, comment string, options []string, rest []byte, err error)
- func ParseKnownHosts(in []byte) (marker string, hosts []string, pubKey ssh.PublicKey, comment string, ...)
- func ParseOpenSSHPrivateKey(key []byte) (crypto.PrivateKey, string, error)
- func ParseOpenSSHPrivateKeyToInfo(key []byte) (openSSHPrivateKey, error)
- func ParseOpenSSHPrivateKeyWithPassword(key []byte, password []byte) (crypto.PrivateKey, string, error)
- func ParsePrivateKey(pemBytes []byte) (ssh.Signer, error)
- func ParsePrivateKeyWithPassphrase(pemBytes, passphrase []byte) (ssh.Signer, error)
- func ParsePublicKey(in []byte) (out ssh.PublicKey, err error)
- func ParseRawPrivateKey(pemBytes []byte) (out any, err error)
- func ParseRawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (out any, err error)
- func ParseSM2AuthorizedKey(in []byte) (out ssh.PublicKey, comment string, options []string, rest []byte, err error)
- func ParseSM2PrivateKeyFromPem(privateKeyPem []byte, pwd []byte) (*sm2.PrivateKey, error)
- func ParseSM2PublicKey(in []byte) (out ssh.PublicKey, err error)
- func ParseSM2RawPrivateKey(pemBytes []byte) (any, error)
- func ParseSM2RawPrivateKeyWithPassphrase(pemBytes, passphrase []byte) (any, error)
- func ParseSSHKeyPem(data []byte) ([]byte, error)
- type BcryptOpts
- type BcryptbinOpts
- type Cipher
- type CipherCBC
- type CipherCTR
- type CipherChacha20poly1305
- func (this CipherChacha20poly1305) BlockSize() int
- func (this CipherChacha20poly1305) Decrypt(key, ciphertext []byte) ([]byte, error)
- func (this CipherChacha20poly1305) Encrypt(key, plaintext []byte) ([]byte, error)
- func (this CipherChacha20poly1305) KeySize() int
- func (this CipherChacha20poly1305) Name() string
- type CipherGCM
- type CipherRC4
- func (this CipherRC4) BlockSize() int
- func (this CipherRC4) Decrypt(key, ciphertext []byte) ([]byte, error)
- func (this CipherRC4) Encrypt(key, plaintext []byte) ([]byte, error)
- func (this CipherRC4) KeySize() int
- func (this CipherRC4) Name() string
- func (this CipherRC4) WithKeySize(keySize int) CipherRC4
- type KDFOpts
- type KDFParameters
- type Key
- type KeyDSA
- type KeyECDSA
- type KeyEdDSA
- type KeyRSA
- type KeySM2
- type Opts
- type PubKeyParser
Constants ¶
This section is empty.
Variables ¶
var ( SSHDESEDE3CBC = "3des-cbc" SSHAES128CBC = "aes128-cbc" SSHAES192CBC = "aes192-cbc" SSHAES256CBC = "aes256-cbc" SSHAES128CTR = "aes128-ctr" SSHAES192CTR = "aes192-ctr" SSHAES256CTR = "aes256-ctr" SSHAES128GCM = "aes128-gcm@openssh.com" SSHAES256GCM = "aes256-gcm@openssh.com" // RC4 = arcfour SSHArcfour = "arcfour" SSHArcfour128 = "arcfour128" SSHArcfour256 = "arcfour256" SSHBlowfishCBC = "blowfish-cbc" // cast5 = cast128 SSHCast128CBC = "cast128-cbc" SSHChacha20poly1305 = "chacha20-poly1305@openssh.com" SSHSM4CBC = "sm4-cbc" SSHSM4CTR = "sm4-ctr" )
var AES128CBC = CipherCBC{ // contains filtered or unexported fields }
AES128CBC is the 128-bit key AES cipher in CBC mode.
var AES128CTR = CipherCTR{ // contains filtered or unexported fields }
AES128CTR is the 128-bit key AES cipher in CTR mode.
var AES128GCM = CipherGCM{ // contains filtered or unexported fields }
AES128GCM is the 128-bit key AES cipher in GCM mode.
var AES192CBC = CipherCBC{ // contains filtered or unexported fields }
AES192CBC is the 192-bit key AES cipher in CBC mode.
var AES192CTR = CipherCTR{ // contains filtered or unexported fields }
AES192CTR is the 192-bit key AES cipher in CTR mode.
var AES256CBC = CipherCBC{ // contains filtered or unexported fields }
AES256CBC is the 256-bit key AES cipher in CBC mode.
var AES256CTR = CipherCTR{ // contains filtered or unexported fields }
AES256CTR is the 256-bit key AES cipher in CTR mode.
var AES256GCM = CipherGCM{ // contains filtered or unexported fields }
AES256GCM is the 256-bit key AES cipher in GCM mode.
var Arcfour = CipherRC4{ // contains filtered or unexported fields }
Arcfour is the (from 1 to 256 bytes) key RC4 cipher.
var Arcfour128 = CipherRC4{ // contains filtered or unexported fields }
Arcfour128 is the 128-bit key RC4 cipher.
var Arcfour256 = CipherRC4{ // contains filtered or unexported fields }
Arcfour256 is the 256-bit key RC4 cipher.
var BlowfishCBC = CipherCBC{ // contains filtered or unexported fields }
BlowfishCBC is the key (from 1 to 56 bytes) blowfish cipher in CBC mode.
var Cast128CBC = CipherCBC{ // contains filtered or unexported fields }
Cast128CBC is the 128-bit key cast5 cipher in CBC mode.
var Chacha20poly1305 = CipherChacha20poly1305{ // contains filtered or unexported fields }
Chacha20poly1305 is the 256-bit chacha20poly1305 cipher.
var DESEDE3CBC = CipherCBC{ // contains filtered or unexported fields }
DESEDE3CBC is the 168-bit key 3DES cipher in CBC mode.
var DefaultOpts = Opts{ Cipher: AES256CTR, KDFOpts: BcryptOpts{ SaltSize: 16, Rounds: 16, }, }
Default options
var (
KeyAlgoSM2 = "ssh-sm2"
)
var SM4CBC = CipherCBC{ // contains filtered or unexported fields }
SM4CBC is the 128-bit SM4 AES cipher in CBC mode.
var SM4CTR = CipherCTR{ // contains filtered or unexported fields }
SM4CTR is the 128-bit SM4 AES cipher in CTR mode.
Functions ¶
func AddPubKeyParser ¶ added in v1.0.2002
func AddPubKeyParser(name string, parser PubKeyParser)
添加解析方式方式 Add PubKey Parser
func EncodeSSHKeyToPem ¶ added in v1.0.1030
Encode SSHKey to pem
func MarshalAuthorizedKey ¶ added in v1.0.2002
Marshal AuthorizedKey
func MarshalAuthorizedKeyWithComment ¶ added in v1.0.2002
创建带信息的 key Marshal AuthorizedKey With Comment
func MarshalOpenSSHPrivateKey ¶
func MarshalOpenSSHPrivateKey(rand io.Reader, key crypto.PrivateKey, comment string) (*pem.Block, error)
Marshal OpenSSH PrivateKey
func MarshalOpenSSHPrivateKeyWithPassword ¶ added in v1.0.1030
func MarshalOpenSSHPrivateKeyWithPassword(rand io.Reader, key crypto.PrivateKey, comment string, password []byte, opts ...Opts) (*pem.Block, error)
Marshal OpenSSH PrivateKey With Password
func NewPublicKey ¶ added in v1.0.2002
RSA | DSA | SM2 | ECDSA | SKECDSA | ED25519 | SKEd25519 CertAlgoRSAv01 | CertAlgoDSAv01 CertAlgoECDSA256v01 | CertAlgoECDSA384v01 CertAlgoECDSA521v01 | CertAlgoSKECDSA256v01 CertAlgoED25519v01 | CertAlgoSKED25519v01
func NewSM2PrivateKey ¶ added in v1.0.2002
func NewSM2PrivateKey(key *sm2.PrivateKey) ssh.Signer
func NewSignerFromKey ¶ added in v1.0.2002
func ParseAuthorizedKey ¶ added in v1.0.2002
func ParseKnownHosts ¶ added in v1.0.2002
func ParseKnownHosts(in []byte) (marker string, hosts []string, pubKey ssh.PublicKey, comment string, rest []byte, err error)
Parse KnownHosts
func ParseOpenSSHPrivateKey ¶
func ParseOpenSSHPrivateKey(key []byte) (crypto.PrivateKey, string, error)
Parse OpenSSH PrivateKey
func ParseOpenSSHPrivateKeyToInfo ¶ added in v1.0.5017
func ParseOpenSSHPrivateKeyWithPassword ¶ added in v1.0.1030
func ParseOpenSSHPrivateKeyWithPassword(key []byte, password []byte) (crypto.PrivateKey, string, error)
Parse OpenSSH PrivateKey With Password
func ParsePrivateKeyWithPassphrase ¶ added in v1.0.2002
func ParsePublicKey ¶ added in v1.0.2002
func ParseRawPrivateKey ¶ added in v1.0.2002
func ParseRawPrivateKeyWithPassphrase ¶ added in v1.0.2002
func ParseSM2AuthorizedKey ¶ added in v1.0.2002
func ParseSM2PrivateKeyFromPem ¶ added in v1.0.2039
func ParseSM2PrivateKeyFromPem(privateKeyPem []byte, pwd []byte) (*sm2.PrivateKey, error)
func ParseSM2PublicKey ¶ added in v1.0.2002
func ParseSM2RawPrivateKey ¶ added in v1.0.2002
func ParseSM2RawPrivateKeyWithPassphrase ¶ added in v1.0.2002
func ParseSSHKeyPem ¶ added in v1.0.1030
Parse SSHKey Pem data
Types ¶
type BcryptOpts ¶
BcryptOpts options
func (BcryptOpts) GetSaltSize ¶
func (this BcryptOpts) GetSaltSize() int
func (BcryptOpts) Name ¶
func (this BcryptOpts) Name() string
type BcryptbinOpts ¶ added in v1.0.5013
BcryptbinOpts options
func (BcryptbinOpts) GetSaltSize ¶ added in v1.0.5013
func (this BcryptbinOpts) GetSaltSize() int
func (BcryptbinOpts) Name ¶ added in v1.0.5013
func (this BcryptbinOpts) Name() string
type Cipher ¶
type Cipher interface { // 名称 // Name Name() string // 值大小 // KeySize KeySize() int // 块大小 // BlockSize BlockSize() int // 加密, 返回: [加密后数据, error] // Encrypt, return [Encrypted, error] Encrypt(key, plaintext []byte) ([]byte, error) // 解密 // Decrypt Decrypt(key, ciphertext []byte) ([]byte, error) }
加密接口 Cipher interface
func GetCipherFromName ¶ added in v1.0.1029
get Cipher from name
func ParseCipher ¶
type CipherCBC ¶
type CipherCBC struct {
// contains filtered or unexported fields
}
cbc mode
type CipherCTR ¶
type CipherCTR struct {
// contains filtered or unexported fields
}
CTR mode
type CipherChacha20poly1305 ¶ added in v1.0.1031
type CipherChacha20poly1305 struct {
// contains filtered or unexported fields
}
Chacha20poly1305 Encrypt/Decrypt
func (CipherChacha20poly1305) BlockSize ¶ added in v1.0.1031
func (this CipherChacha20poly1305) BlockSize() int
BlockSize
func (CipherChacha20poly1305) Decrypt ¶ added in v1.0.1031
func (this CipherChacha20poly1305) Decrypt(key, ciphertext []byte) ([]byte, error)
Decrypt
func (CipherChacha20poly1305) Encrypt ¶ added in v1.0.1031
func (this CipherChacha20poly1305) Encrypt(key, plaintext []byte) ([]byte, error)
Encrypt
func (CipherChacha20poly1305) KeySize ¶ added in v1.0.1031
func (this CipherChacha20poly1305) KeySize() int
KeySize
func (CipherChacha20poly1305) Name ¶ added in v1.0.1031
func (this CipherChacha20poly1305) Name() string
oid name
type CipherGCM ¶ added in v1.0.1031
type CipherGCM struct {
// contains filtered or unexported fields
}
gcm mode
type CipherRC4 ¶ added in v1.0.1031
type CipherRC4 struct {
// contains filtered or unexported fields
}
CipherRC4 Encrypt/Decrypt
func (CipherRC4) WithKeySize ¶ added in v1.0.1031
With KeySize
type KDFOpts ¶
type KDFOpts interface { // 名称 // Name Name() string // 生成密钥 // DeriveKey func DeriveKey(random io.Reader, password []byte, size int) (key []byte, params string, err error) // 随机数大小 // Get SaltSize GetSaltSize() int }
KDF 设置接口 KDF Options
type KDFParameters ¶
type KDFParameters interface { // 生成密钥 // DeriveKey func DeriveKey(password []byte, kdfOpts string, size int) (key []byte, err error) }
数据接口 KDF Parameters
func ParsePBKDF ¶ added in v1.0.5013
func ParsePBKDF(kdfName string) (KDFParameters, error)
Parse PBKDF
type Key ¶
type Key interface { // 包装 // Marshal Marshal(key crypto.PrivateKey, comment string) (string, []byte, []byte, error) // 解析 // Parse Parse(data []byte) (crypto.PrivateKey, string, error) }
Key 接口 Key interface
func ParseKeyType ¶ added in v1.0.5013
type KeyDSA ¶ added in v1.0.5015
type KeyDSA struct{}
DSA key
type KeyECDSA ¶ added in v1.0.5013
type KeyECDSA struct{}
ecdsa key
type KeyEdDSA ¶ added in v1.0.5013
type KeyEdDSA struct{}
EdDSA key
type KeyRSA ¶ added in v1.0.5013
type KeyRSA struct{}
RSA key
type KeySM2 ¶ added in v1.0.1031
type KeySM2 struct{}
SM2 key
type PubKeyParser ¶ added in v1.0.2002
解析方式 PubKey Parser
func GetPubKeyParser ¶ added in v1.0.2002
func GetPubKeyParser(name string) PubKeyParser
获取解析方式方式 Get PubKey Parser