kcrypto

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2025 License: AGPL-3.0 Imports: 14 Imported by: 0

README

kcrypto

crypto warp

Documentation

Index

Constants

View Source
const (
	KeyTypeEd25519                = "ed25519"
	KeyTypeECDSA_SHA2_P256_COMPAT = "ecdsa-sha2-nistp256"
	KeyTypeECDSA_SHA2_P256        = "ecdsa"
	KeyTypeRSASSA_PSS_SHA256      = "rsa"
	KeySchemeEd25519              = "ed25519"
	KeySchemeECDSA_SHA2_P256      = "ecdsa-sha2-nistp256"
	KeySchemeECDSA_SHA2_P384      = "ecdsa-sha2-nistp384"
	KeySchemeRSASSA_PSS_SHA256    = "rsassa-pss-sha256"
)
View Source
const (
	ED25519_TYPE    = 0
	RSA_TYPE        = 3
	ECDSA_P256_TYPE = 1
	ECDSA_TYPE      = 2
	INVALID_TYPE    = 4
)
View Source
const (
	RSAKeyLength = 2048
)

Variables

View Source
var (
	ErrorEmptyKey = errors.New("error on key empty, check if the key has been initialized")
	// ErrorUnsupportedKeyType means we don't supported this type of key
	ErrorUnsupportedKeyType = errors.New("provided key type not supported")
)
View Source
var (
	InvalidCryptoInvalid = "INVALID"

	CryptoInfoList = []CryptoInfo{
		{
			Short:  "ed25519",
			Type:   KeyTypeEd25519,
			Schema: KeySchemeEd25519,
		},
		{
			Short:  "ecdsa-p256",
			Type:   KeyTypeECDSA_SHA2_P256_COMPAT,
			Schema: KeySchemeECDSA_SHA2_P256,
		},
		{
			Short:  "ecdsa",
			Type:   KeyTypeECDSA_SHA2_P256,
			Schema: KeySchemeECDSA_SHA2_P384,
		},
		{
			Short:  "rsa",
			Type:   KeyTypeRSASSA_PSS_SHA256,
			Schema: KeySchemeRSASSA_PSS_SHA256,
		},
	}
)

Functions

func CryptoSchemaList

func CryptoSchemaList(splite string) string

func CryptoShortList

func CryptoShortList(splite string) string

func CryptoTypeList

func CryptoTypeList(splite string) string

func GenKeyPair

func GenKeyPair(ty CryptoType, privatePath, publicPath string) error

func LoadKeyInfo

func LoadKeyInfo(info *KeyInfo) (PrivateKey, PublicKey, error)

func LoadKeyInfoFile

func LoadKeyInfoFile(filePath string) (PrivateKey, PublicKey, error)

func ShowKeyInfo

func ShowKeyInfo(ki *KeyInfo) error

func ShowKeyInfoFile

func ShowKeyInfoFile(dst string) error

Types

type CryptoInfo

type CryptoInfo struct {
	Short  string
	Type   string
	Schema string
}

type CryptoType

type CryptoType int

func (CryptoType) Boolean

func (l CryptoType) Boolean() bool

func (CryptoType) Schema

func (l CryptoType) Schema() string

func (*CryptoType) Set

func (l *CryptoType) Set(value string) error

func (*CryptoType) SetInt

func (l *CryptoType) SetInt(value int) error

func (*CryptoType) SetScheme

func (l *CryptoType) SetScheme(value string) error

func (*CryptoType) SetShort

func (l *CryptoType) SetShort(value string) error

func (CryptoType) Short

func (l CryptoType) Short() string

func (*CryptoType) String

func (l *CryptoType) String() string

func (CryptoType) Type

func (l CryptoType) Type() string

type Ed25519PrivKey

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

func (*Ed25519PrivKey) Empty

func (p *Ed25519PrivKey) Empty() bool

func (*Ed25519PrivKey) Generate

func (p *Ed25519PrivKey) Generate() error

func (*Ed25519PrivKey) Key

func (p *Ed25519PrivKey) Key() crypto.PrivateKey

func (*Ed25519PrivKey) KeyInfo

func (p *Ed25519PrivKey) KeyInfo() (*KeyInfo, error)

func (*Ed25519PrivKey) ParsePem

func (p *Ed25519PrivKey) ParsePem(key []byte) error

func (*Ed25519PrivKey) Pem

func (p *Ed25519PrivKey) Pem() ([]byte, error)

func (*Ed25519PrivKey) Public

func (p *Ed25519PrivKey) Public() PublicKey

func (*Ed25519PrivKey) SetKey

func (p *Ed25519PrivKey) SetKey(k crypto.PrivateKey) error

func (*Ed25519PrivKey) Signer

func (p *Ed25519PrivKey) Signer() crypto.Signer

func (*Ed25519PrivKey) Type

func (p *Ed25519PrivKey) Type() CryptoType

type Ed25519PubKey

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

func (*Ed25519PubKey) Empty

func (p *Ed25519PubKey) Empty() bool

func (*Ed25519PubKey) Key

func (p *Ed25519PubKey) Key() crypto.PublicKey

func (*Ed25519PubKey) KeyInfo

func (p *Ed25519PubKey) KeyInfo() (*KeyInfo, error)

func (*Ed25519PubKey) ParsePem

func (p *Ed25519PubKey) ParsePem(key []byte) error

func (*Ed25519PubKey) Pem

func (p *Ed25519PubKey) Pem() ([]byte, error)

func (*Ed25519PubKey) SetKey

func (p *Ed25519PubKey) SetKey(k crypto.PublicKey) error

SetKey set raw public key

func (*Ed25519PubKey) Type

func (p *Ed25519PubKey) Type() CryptoType

type KeyInfo

type KeyInfo struct {
	Type   string            `json:"keytype"`
	Value  map[string]string `json:"keyval"`
	Scheme string            `json:"scheme"`
}

KeyInfo is the manifest structure of a single key

func NewKeyInfo

func NewKeyInfo() *KeyInfo

func (*KeyInfo) CheckType

func (ki *KeyInfo) CheckType() (CryptoType, error)

Load loads a KeyInfo object from a JSON file

func (*KeyInfo) Empty

func (ki *KeyInfo) Empty() bool

func (*KeyInfo) ID

func (ki *KeyInfo) ID() (string, error)

ID returns the hash id of the key

func (*KeyInfo) IsPrivate

func (ki *KeyInfo) IsPrivate() bool

IsPrivate detect if this is a private key

func (*KeyInfo) IsPublic

func (ki *KeyInfo) IsPublic() bool

IsPrivate detect if this is a private key

func (*KeyInfo) Load

func (ki *KeyInfo) Load(src string) error

Load loads a KeyInfo object from a JSON file

func (*KeyInfo) PrivData

func (ki *KeyInfo) PrivData() (string, error)

func (*KeyInfo) PubData

func (ki *KeyInfo) PubData() (string, error)

Load loads a KeyInfo object from a JSON file

func (*KeyInfo) Save

func (ki *KeyInfo) Save(dst string, privMode os.FileMode) error

Save saves a KeyInfo object to a JSON file

type PrivateKey

type PrivateKey interface {
	Empty() bool
	// Type returns the type of the key, e.g. RSA
	Type() CryptoType

	// Signer returns the signer of the private key
	Signer() crypto.Signer
	// Public returns public key of the PrivKey
	Public() PublicKey

	// Key returns the raw public key
	Key() crypto.PrivateKey

	SetKey(crypto.PrivateKey) error

	// Pem returns the raw private key in PEM format
	Pem() ([]byte, error)
	// Pem returns the raw private key in PEM format
	ParsePem([]byte) error
	// KeyInfo pack KeyInfo for public key
	KeyInfo() (*KeyInfo, error)

	/// Generate private key for this key
	Generate() error
}

PrivKey is the private key that provide signature method

func NewEd25519PrivKey

func NewEd25519PrivKey() PrivateKey

func NewPrivateKey

func NewPrivateKey(ty CryptoType) (PrivateKey, error)

NewPrivateKey

func NewRSAPrivKey

func NewRSAPrivKey() PrivateKey

type PublicKey

type PublicKey interface {
	// Type returns the type of the key, e.g. RSA
	Type() CryptoType

	// Key returns the raw public key
	Key() crypto.PublicKey

	// SetKey set raw public key
	SetKey(crypto.PublicKey) error

	// Pem returns the raw private key in PEM format
	Pem() ([]byte, error)

	// Pem returns the raw private key in PEM format
	ParsePem([]byte) error

	// KeyInfo pack KeyInfo for public key
	KeyInfo() (*KeyInfo, error)
}

PublicKey is a public key available to KMOPT

func NewEd25519PubKey

func NewEd25519PubKey() PublicKey

func NewPublicKey

func NewPublicKey(ty CryptoType) (PublicKey, error)

func NewRSAPublicKey

func NewRSAPublicKey() PublicKey

type RSAPrivKey

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

func (*RSAPrivKey) Empty

func (p *RSAPrivKey) Empty() bool

func (*RSAPrivKey) Generate

func (p *RSAPrivKey) Generate() error

func (*RSAPrivKey) Key

func (p *RSAPrivKey) Key() crypto.PrivateKey

func (*RSAPrivKey) KeyInfo

func (p *RSAPrivKey) KeyInfo() (*KeyInfo, error)

func (*RSAPrivKey) ParsePem

func (p *RSAPrivKey) ParsePem(key []byte) error

func (*RSAPrivKey) Pem

func (p *RSAPrivKey) Pem() ([]byte, error)

func (*RSAPrivKey) Public

func (p *RSAPrivKey) Public() PublicKey

func (*RSAPrivKey) SetKey

func (p *RSAPrivKey) SetKey(k crypto.PrivateKey) error

func (*RSAPrivKey) Signer

func (p *RSAPrivKey) Signer() crypto.Signer

func (*RSAPrivKey) Type

func (p *RSAPrivKey) Type() CryptoType

type RSAPubKey

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

func (*RSAPubKey) Empty

func (p *RSAPubKey) Empty() bool

func (*RSAPubKey) Key

func (p *RSAPubKey) Key() crypto.PublicKey

func (*RSAPubKey) KeyInfo

func (p *RSAPubKey) KeyInfo() (*KeyInfo, error)

func (*RSAPubKey) ParsePem

func (p *RSAPubKey) ParsePem(key []byte) error

func (*RSAPubKey) Pem

func (p *RSAPubKey) Pem() ([]byte, error)

func (*RSAPubKey) SetKey

func (p *RSAPubKey) SetKey(k crypto.PublicKey) error

SetKey set raw public key

func (*RSAPubKey) Type

func (p *RSAPubKey) Type() CryptoType

Jump to

Keyboard shortcuts

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