crypto

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: MPL-2.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DefaultAuthoritiesKeysFileName = "authorities_keys"
	SharedThreshold                = 1
)
View Source
const (
	// AES256KeySize is the size of the AES256 key.
	AES256KeySize = 32
	// OpenSSLSaltSize is the size of the salt used by OpenSSL.
	OpenSSLSaltSize = 8
	// OpenSSLPDKF2Iter is the number of iterations used by OpenSSL.
	OpenSSLPDKF2Iter = 10000
	// OpenSSLSaltedPrefix is the prefix used by OpenSSL.
	OpenSSLSaltedPrefix = "Salted__"
)
View Source
const (
	DefaultRealmsKeysFileName = "realms_keys"
)

Variables

View Source
var (
	ErrPKCS7DataIsNotAligned = errors.New("is not block-aligned")
	ErrPKCS7InvalidPadding   = errors.New("invalid padding on input")
)
View Source
var (
	ErrKeyNotFound     = errors.New("key not found")
	ErrKeyNotCryptoKey = errors.New("key is not a crypto key")
	ErrKeyNotRSAKey    = errors.New("key is not a RSA key")
)
View Source
var (
	ErrSecretTooLong = errors.New("secret too long")
	ErrEmptySecret   = errors.New("empty secret")
)
View Source
var (
	ErrDecodePEM = errors.New("unable to decode pem file")
	ErrNoRSAKey  = errors.New("not an RSA private key")
)
View Source
var (
	ErrEmptyData = errors.New("empty data")
)

Errors

View Source
var ErrPKCS7BlockSize = errors.New("invalid pkcs7 block size")
View Source
var ErrSaltPrefixMismatch = errors.New("salt prefix mismatch")

Functions

func ConvSSHPubKeyToRSAPubKey

func ConvSSHPubKeyToRSAPubKey(key ssh.PublicKey) (*rsa.PublicKey, error)

ConvSSHPubKeyToRSAPubKey returns the RSA public key from the ssh public key.

func DecryptAES256CBC

func DecryptAES256CBC(r io.Reader, w io.Writer, secret []byte) error

DecryptAES256CBC aes-cbc-decrypts the data with the secret. openssl enc -d -aes-256-cbc -pass zzz ...

func DecryptRSAEncodedSecret

func DecryptRSAEncodedSecret(key *rsa.PrivateKey, encodedEncryptedSecret string) ([]byte, error)

DecryptRSAEncodedSecret decrypts an encoded encrypted secret using a RSA private key. The result is aт original secret.

func DecryptSecret

func DecryptSecret(key *rsa.PrivateKey, encryptedSecret []byte) ([]byte, error)

DecryptSecret decrypts the secret with the private key.

func EncryptAES256CBC

func EncryptAES256CBC(r io.Reader, w io.Writer, secret []byte) error

EncryptAES256CBC aes-cbc-encrypts the data with the secret. openssl enc -aes-256-cbc -pass zzz ...

func EncryptSecret

func EncryptSecret(key *rsa.PublicKey, secret []byte) ([]byte, error)

EncryptSecret encrypts the secret with the public key.

func EncryptSecretForAuthorities

func EncryptSecretForAuthorities(auths []*RSAPublicKey, secret []byte) (snapCore.EncryptedSecretPair, error)

EncryptSecretForAuthorities encrypts the secret with each authority's public key. The result is a map of encrypted secrets and authority fingerprints.

func FindPubKeyInFile

func FindPubKeyInFile(path string, fp string) (*rsa.PublicKey, error)

FindPubKeyInFile returns the public RSA key by fingerprint from the authorized_keys format file.

func GenSecret

func GenSecret(sz int) ([]byte, error)

GenSecret creates a new secret of the specified size.

func GetPublicRSAKeyByFingerprint

func GetPublicRSAKeyByFingerprint(data []byte, fp string) (*rsa.PublicKey, error)

GetPublicRSAKeyByFingerprint returns the public RSA key by fingerprint from the authorized_keys format data.

func ReadPrivateSSHKeyFile

func ReadPrivateSSHKeyFile(path string) (*rsa.PrivateKey, error)

Types

type RSAPrivateKeys

type RSAPrivateKeys struct {
	Key         *rsa.PrivateKey
	FingerPrint string
}

RSAPrivate is a map of RSA private keys.

type RSAPublicKey

type RSAPublicKey struct {
	Key         *rsa.PublicKey
	FingerPrint string
}

RSAPublicKey is a map of RSA public keys.

func GetRSAPublicKeysList

func GetRSAPublicKeysList(data []byte) ([]*RSAPublicKey, error)

GetRSAPublicKeyList returns the list of RSA public keys from the authorized_keys format data.

func ReadAuthoritiesPubKeyFile

func ReadAuthoritiesPubKeyFile(path string) ([]*RSAPublicKey, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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