Documentation ¶
Overview ¶
Package crypto provides tools for data encryption and certificates management
Index ¶
- Constants
- Variables
- func CreateRsaKey() (*rsa.PrivateKey, error)
- func DeleteKeyringPassword(service string, user string) error
- func EncodePrivate(password []byte, key crypto.PrivateKey) ([]byte, error)
- func GenerateCACertificate(t *Template) (*x509.Certificate, error)
- func GenerateServiceCertificate(t *Template) (*x509.Certificate, error)
- func GetKeyringPassword(service string, user string, createIfNotExist bool) ([]byte, error)
- func GetSignature(key *ecdsa.PrivateKey, data []byte) (string, error)
- func KeyFromPassword(password []byte, l int) []byte
- func LoadCertificate(file string) (*x509.Certificate, error)
- func LoadPrivateKey(password []byte, file string) (crypto.PrivateKey, error)
- func Md5(data []byte) []byte
- func NewEcdsaPrivateKey(alg string) (*ecdsa.PrivateKey, error)
- func NewLegacyAESGCMMaterials(info *encryption.NodeInfo) *legacyReadMaterials
- func Open(key []byte, nonce []byte, cipherData []byte) ([]byte, error)
- func ParsePrivate(password []byte, bytes []byte) (crypto.PrivateKey, error)
- func PublicKeyFromRsaKey(privateKey *rsa.PrivateKey) rsa.PublicKey
- func RandomBytes(size int) ([]byte, error)
- func RsaKeyFromPEM(pemString string) (*rsa.PrivateKey, error)
- func RsaKeyFromPEMFile(filename string) (*rsa.PrivateKey, error)
- func RsaKeyToPEM(key *rsa.PrivateKey, filename ...string) (string, error)
- func RsaPublicKeyToPEM(pubKey rsa.PublicKey, filename ...string) (string, error)
- func Seal(key []byte, data []byte) ([]byte, error)
- func SealWithNonce(key []byte, nonce []byte, data []byte) ([]byte, error)
- func SetKeyringPassword(service string, user string, password []byte) error
- func StoreCertificate(cert *x509.Certificate, file string, perm os.FileMode) error
- func StorePrivateKey(key crypto.PrivateKey, password []byte, file string) error
- func VerifySignature(data []byte, key *ecdsa.PublicKey, signature string) bool
- type AESGCMEncryptionMaterials
- func (m *AESGCMEncryptionMaterials) CalculateOutputSize(plainSize int64, user string) int64
- func (m *AESGCMEncryptionMaterials) Close() error
- func (m *AESGCMEncryptionMaterials) Read(b []byte) (int, error)
- func (m *AESGCMEncryptionMaterials) SetPlainRange(offset, length int64)
- func (m *AESGCMEncryptionMaterials) SetupDecryptMode(workingKey []byte, stream io.Reader) error
- func (m *AESGCMEncryptionMaterials) SetupEncryptMode(workingKey []byte, stream io.Reader) error
- type BlockHandler
- type EncryptedBlock
- type EncryptedBlockHeader
- type EncryptedBlockHeaderOption
- func (op *EncryptedBlockHeaderOption) GetID() uint8
- func (op *EncryptedBlockHeaderOption) GetValue() []byte
- func (op *EncryptedBlockHeaderOption) HasValue() bool
- func (op *EncryptedBlockHeaderOption) IsTheLast() bool
- func (op *EncryptedBlockHeaderOption) Read(reader io.Reader) (int, error)
- func (op *EncryptedBlockHeaderOption) SetId(id uint8) error
- func (op *EncryptedBlockHeaderOption) SetIsTheLast(last bool)
- func (op *EncryptedBlockHeaderOption) SetValue(value []byte) error
- func (op *EncryptedBlockHeaderOption) Write(writer io.Writer) (int, error)
- type Options
- type Template
Constants ¶
const ( AESGCMAuthTagSize = 16 AESGCMNonceSize = 12 )
Variables ¶
var SALT = []byte{224, 32, 00, 33, 78, 3, 25, 56, 54, 5, 54, 9, 79, 76, 189, 8}
Functions ¶
func CreateRsaKey ¶
func CreateRsaKey() (*rsa.PrivateKey, error)
CreateRsaKey generates a new private key.
func DeleteKeyringPassword ¶
DeleteKeyringPassword removes all key that matches "service" and "user".
func EncodePrivate ¶
func EncodePrivate(password []byte, key crypto.PrivateKey) ([]byte, error)
func GenerateCACertificate ¶
func GenerateCACertificate(t *Template) (*x509.Certificate, error)
GenerateCACertificate generates a certificate for a CA.
func GenerateServiceCertificate ¶
func GenerateServiceCertificate(t *Template) (*x509.Certificate, error)
GenerateServiceCertificate generates a certificate for a service.
func GetKeyringPassword ¶
GetKeyringPassword retrieves a password from the keyring. If no key matches "service" and "user" and if createIfNotExist flag is set, a new key is generated and returned.
func GetSignature ¶
func GetSignature(key *ecdsa.PrivateKey, data []byte) (string, error)
func KeyFromPassword ¶
func LoadCertificate ¶
func LoadCertificate(file string) (*x509.Certificate, error)
LoadCertificate loads file contenant and decodes it into a x509.Certificate.
func LoadPrivateKey ¶
func LoadPrivateKey(password []byte, file string) (crypto.PrivateKey, error)
LoadPrivateKey loads the encrypted private key from the passed file and decrypts it.
func NewEcdsaPrivateKey ¶
func NewEcdsaPrivateKey(alg string) (*ecdsa.PrivateKey, error)
func NewLegacyAESGCMMaterials ¶ added in v1.6.1
func NewLegacyAESGCMMaterials(info *encryption.NodeInfo) *legacyReadMaterials
NewLegacyAESGCMMaterials creates an encryption materials that uses legacy material
func ParsePrivate ¶
func ParsePrivate(password []byte, bytes []byte) (crypto.PrivateKey, error)
func PublicKeyFromRsaKey ¶
func PublicKeyFromRsaKey(privateKey *rsa.PrivateKey) rsa.PublicKey
PublicKeyFromRsaKey extracts the public key.
func RandomBytes ¶
func RsaKeyFromPEM ¶
func RsaKeyFromPEM(pemString string) (*rsa.PrivateKey, error)
RsaKeyFromPEM parses a PEM string.
func RsaKeyFromPEMFile ¶
func RsaKeyFromPEMFile(filename string) (*rsa.PrivateKey, error)
RsaKeyFromPEMFile loads a PEM file and parses the private key.
func RsaKeyToPEM ¶
func RsaKeyToPEM(key *rsa.PrivateKey, filename ...string) (string, error)
RsaKeyToPEM encodes the private key in PEM format.
func RsaPublicKeyToPEM ¶
RsaPublicKeyToPEM encodes the public key to PEM format.
func SealWithNonce ¶ added in v1.6.0
func SetKeyringPassword ¶
SetKeyringPassword base64-encodes password and stores it.
func StoreCertificate ¶
StoreCertificate encodes certificate and stores the result in file.
func StorePrivateKey ¶
func StorePrivateKey(key crypto.PrivateKey, password []byte, file string) error
StorePrivateKey encrypts the private key and stores it in the returned file.
Types ¶
type AESGCMEncryptionMaterials ¶ added in v1.6.0
type AESGCMEncryptionMaterials struct {
// contains filtered or unexported fields
}
AESGCMEncryptionMaterials implements AES-GCM encryption
func NewAESGCMMaterials ¶
func NewAESGCMMaterials(info *encryption.NodeInfo, blockHandler BlockHandler) *AESGCMEncryptionMaterials
NewAESGCMMaterials creates an encryption materials that use AES GCM.
func (*AESGCMEncryptionMaterials) CalculateOutputSize ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) CalculateOutputSize(plainSize int64, user string) int64
func (*AESGCMEncryptionMaterials) Close ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) Close() error
func (*AESGCMEncryptionMaterials) Read ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) Read(b []byte) (int, error)
func (*AESGCMEncryptionMaterials) SetPlainRange ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) SetPlainRange(offset, length int64)
func (*AESGCMEncryptionMaterials) SetupDecryptMode ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) SetupDecryptMode(workingKey []byte, stream io.Reader) error
func (*AESGCMEncryptionMaterials) SetupEncryptMode ¶ added in v1.6.0
func (m *AESGCMEncryptionMaterials) SetupEncryptMode(workingKey []byte, stream io.Reader) error
type BlockHandler ¶ added in v1.6.0
type BlockHandler interface { SendKey(key *encryption.NodeKey) error SendBlock(block *encryption.Block) error Close() error }
type EncryptedBlock ¶ added in v1.6.0
type EncryptedBlock struct { Header *EncryptedBlockHeader HeaderSize uint32 Payload []byte }
EncryptedBlock describes block
func (*EncryptedBlock) GetPayloadLength ¶ added in v1.6.0
func (b *EncryptedBlock) GetPayloadLength() uint32
func (*EncryptedBlock) Read ¶ added in v1.6.0
func (b *EncryptedBlock) Read(reader io.Reader) (int, error)
func (*EncryptedBlock) SetPayload ¶ added in v1.6.0
func (b *EncryptedBlock) SetPayload(payload []byte) error
type EncryptedBlockHeader ¶ added in v1.6.0
type EncryptedBlockHeader struct { Options *Options Nonce []byte // contains filtered or unexported fields }
EncryptedBlockHeader describes headers
func (*EncryptedBlockHeader) GetDataLength ¶ added in v1.6.0
func (h *EncryptedBlockHeader) GetDataLength() uint32
func (*EncryptedBlockHeader) Read ¶ added in v1.6.0
func (h *EncryptedBlockHeader) Read(reader io.Reader) (int, error)
func (*EncryptedBlockHeader) String ¶ added in v1.6.0
func (h *EncryptedBlockHeader) String() string
type EncryptedBlockHeaderOption ¶ added in v1.6.0
type EncryptedBlockHeaderOption struct {
// contains filtered or unexported fields
}
EncryptedBlockHeaderOption describes header
func (*EncryptedBlockHeaderOption) GetID ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) GetID() uint8
func (*EncryptedBlockHeaderOption) GetValue ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) GetValue() []byte
func (*EncryptedBlockHeaderOption) HasValue ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) HasValue() bool
func (*EncryptedBlockHeaderOption) IsTheLast ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) IsTheLast() bool
func (*EncryptedBlockHeaderOption) Read ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) Read(reader io.Reader) (int, error)
func (*EncryptedBlockHeaderOption) SetId ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) SetId(id uint8) error
func (*EncryptedBlockHeaderOption) SetIsTheLast ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) SetIsTheLast(last bool)
func (*EncryptedBlockHeaderOption) SetValue ¶ added in v1.6.0
func (op *EncryptedBlockHeaderOption) SetValue(value []byte) error