cryptogo

package module
Version: v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: Apache-2.0 Imports: 24 Imported by: 17

Documentation

Index

Constants

View Source
const (
	AES_128_KEY_SIZE_BITS  = 128
	AES_128_KEY_SIZE_BYTES = AES_128_KEY_SIZE_BITS / 8

	AES_256_KEY_SIZE_BITS  = 256
	AES_256_KEY_SIZE_BYTES = AES_256_KEY_SIZE_BITS / 8

	MIN_PASSWORD = 12
)

Variables

View Source
var CompressionAlgorithm_name = map[int32]string{
	0: "UNKNOWN_COMPRESSION",
}
View Source
var CompressionAlgorithm_value = map[string]int32{
	"UNKNOWN_COMPRESSION": 0,
}
View Source
var EncryptionAlgorithm_name = map[int32]string{
	0: "UNKNOWN_ENCRYPTION",
	1: "AES_128_GCM_NOPADDING",
	2: "PBKDF2WITHHMACSHA1",
	3: "RSA_ECB_OAEPPADDING",
	4: "AES_256_GCM_NOPADDING",
}
View Source
var EncryptionAlgorithm_value = map[string]int32{
	"UNKNOWN_ENCRYPTION":    0,
	"AES_128_GCM_NOPADDING": 1,
	"PBKDF2WITHHMACSHA1":    2,
	"RSA_ECB_OAEPPADDING":   3,
	"AES_256_GCM_NOPADDING": 4,
}
View Source
var PrivateKeyFormat_name = map[int32]string{
	0: "UNKNOWN_PRIVATE_KEY_FORMAT",
	1: "PKCS1_PRIVATE",
	2: "PKCS8",
}
View Source
var PrivateKeyFormat_value = map[string]int32{
	"UNKNOWN_PRIVATE_KEY_FORMAT": 0,
	"PKCS1_PRIVATE":              1,
	"PKCS8":                      2,
}
View Source
var PublicKeyFormat_name = map[int32]string{
	0: "UNKNOWN_PUBLIC_KEY_FORMAT",
	1: "PKCS1_PUBLIC",
	2: "PKIX",
	3: "X509",
}
View Source
var PublicKeyFormat_value = map[string]int32{
	"UNKNOWN_PUBLIC_KEY_FORMAT": 0,
	"PKCS1_PUBLIC":              1,
	"PKIX":                      2,
	"X509":                      3,
}
View Source
var SignatureAlgorithm_name = map[int32]string{
	0: "UNKNOWN_SIGNATURE",
	1: "SHA512WITHRSA",
	2: "SHA512WITHRSA_PSS",
}
View Source
var SignatureAlgorithm_value = map[string]int32{
	"UNKNOWN_SIGNATURE": 0,
	"SHA512WITHRSA":     1,
	"SHA512WITHRSA_PSS": 2,
}

Functions

func CreateRSAPrivateKey

func CreateRSAPrivateKey(directory, name string, password []byte) (*rsa.PrivateKey, error)

func CreateSignature

func CreateSignature(algorithm SignatureAlgorithm, privateKey *rsa.PrivateKey, data []byte) ([]byte, error)

func DecryptAESGCM

func DecryptAESGCM(key, encrypted []byte) ([]byte, error)

func DecryptKey

func DecryptKey(algorithm EncryptionAlgorithm, secret []byte, key *rsa.PrivateKey) ([]byte, error)

func DecryptPayload

func DecryptPayload(algorithm EncryptionAlgorithm, payload []byte, key []byte) ([]byte, error)

func EncryptAESGCM

func EncryptAESGCM(key, payload []byte) ([]byte, error)

func ExportKeys

func ExportKeys(host, keystore, name string, password []byte) (string, error)

func GenerateRandomKey

func GenerateRandomKey(bytes int) ([]byte, error)

func HasRSAPrivateKey

func HasRSAPrivateKey(directory, name string) bool

func Hash

func Hash(data []byte) []byte

func HashProtobuf

func HashProtobuf(protobuf proto.Message) ([]byte, error)

func ImportKeys

func ImportKeys(host, keystore, name, accessCode string) error

func KeyShareHandler

func KeyShareHandler(keys KeyShareStore, timeout time.Duration) func(w http.ResponseWriter, r *http.Request)

func ListRSAPrivateKeys

func ListRSAPrivateKeys(directory string) ([]string, error)

func LoadRSAPrivateKey added in v1.2.0

func LoadRSAPrivateKey(directory, name string) (*rsa.PrivateKey, error)

func ParseRSAPrivateKey

func ParseRSAPrivateKey(format PrivateKeyFormat, privateKey []byte) (*rsa.PrivateKey, error)

func ParseRSAPublicKey

func ParseRSAPublicKey(format PublicKeyFormat, publicKey []byte) (*rsa.PublicKey, error)

func Password added in v1.2.0

func Password() ([]byte, error)

func PrivateKeyToRSAPrivateKey

func PrivateKeyToRSAPrivateKey(key interface{}) (*rsa.PrivateKey, error)

func PublicKeyToRSAPublicKey

func PublicKeyToRSAPublicKey(key interface{}) (*rsa.PublicKey, error)

func RSAPrivateKey added in v1.2.0

func RSAPrivateKey(directory, name string, password []byte) (*rsa.PrivateKey, error)

func RSAPrivateKeyFromPKCS1Bytes

func RSAPrivateKeyFromPKCS1Bytes(data []byte) (*rsa.PrivateKey, error)

func RSAPrivateKeyFromPKCS8Bytes

func RSAPrivateKeyFromPKCS8Bytes(data []byte) (*rsa.PrivateKey, error)

func RSAPrivateKeyToPEM

func RSAPrivateKeyToPEM(privateKey *rsa.PrivateKey, password []byte) (*pem.Block, error)

func RSAPrivateKeyToPKCS1Bytes

func RSAPrivateKeyToPKCS1Bytes(privateKey *rsa.PrivateKey) []byte

func RSAPrivateKeyToPKCS8Bytes

func RSAPrivateKeyToPKCS8Bytes(privateKey *rsa.PrivateKey) ([]byte, error)

func RSAPublicKeyFromPKCS1Bytes

func RSAPublicKeyFromPKCS1Bytes(data []byte) (*rsa.PublicKey, error)

func RSAPublicKeyFromPKIXBytes

func RSAPublicKeyFromPKIXBytes(data []byte) (*rsa.PublicKey, error)

func RSAPublicKeyToPEM

func RSAPublicKeyToPEM(publicKey *rsa.PublicKey) (*pem.Block, error)

func RSAPublicKeyToPKCS1Bytes

func RSAPublicKeyToPKCS1Bytes(publicKey *rsa.PublicKey) []byte

func RSAPublicKeyToPKIXBytes

func RSAPublicKeyToPKIXBytes(publicKey *rsa.PublicKey) ([]byte, error)

func RandomString

func RandomString(size uint) (string, error)

func ReadPEM

func ReadPEM(filename string) (*pem.Block, error)

func ReadPassword

func ReadPassword(prompt string) ([]byte, error)

func VerifySignature

func VerifySignature(algorithm SignatureAlgorithm, publicKey *rsa.PublicKey, data, signature []byte) error

func WritePEM

func WritePEM(key *pem.Block, filename string) error

func WriteRSAPrivateKey

func WriteRSAPrivateKey(privateKey *rsa.PrivateKey, directory, name string, password []byte) error

Types

type CompressionAlgorithm

type CompressionAlgorithm int32
const (
	CompressionAlgorithm_UNKNOWN_COMPRESSION CompressionAlgorithm = 0
)

func (CompressionAlgorithm) EnumDescriptor

func (CompressionAlgorithm) EnumDescriptor() ([]byte, []int)

func (CompressionAlgorithm) String

func (x CompressionAlgorithm) String() string

type EncryptionAlgorithm

type EncryptionAlgorithm int32
const (
	EncryptionAlgorithm_UNKNOWN_ENCRYPTION    EncryptionAlgorithm = 0
	EncryptionAlgorithm_AES_128_GCM_NOPADDING EncryptionAlgorithm = 1
	EncryptionAlgorithm_PBKDF2WITHHMACSHA1    EncryptionAlgorithm = 2
	EncryptionAlgorithm_RSA_ECB_OAEPPADDING   EncryptionAlgorithm = 3
	EncryptionAlgorithm_AES_256_GCM_NOPADDING EncryptionAlgorithm = 4
)

func (EncryptionAlgorithm) EnumDescriptor

func (EncryptionAlgorithm) EnumDescriptor() ([]byte, []int)

func (EncryptionAlgorithm) String

func (x EncryptionAlgorithm) String() string

type ErrExportFailed added in v1.2.1

type ErrExportFailed struct {
	StatusCode int
	Status     string
}

ErrExportFailed is returned when the key cannot be exported.

func (ErrExportFailed) Error added in v1.2.1

func (e ErrExportFailed) Error() string

type ErrPasswordTooShort added in v1.2.1

type ErrPasswordTooShort struct {
	Size, Min int
}

ErrPasswordTooShort is returned when the password doesn't have enough characters.

func (ErrPasswordTooShort) Error added in v1.2.1

func (e ErrPasswordTooShort) Error() string

type ErrPasswordsDoNotMatch added in v1.2.1

type ErrPasswordsDoNotMatch struct {
}

ErrPasswordsDoNotMatch is returned when the password doesn't match the confirmation.

func (ErrPasswordsDoNotMatch) Error added in v1.2.1

func (e ErrPasswordsDoNotMatch) Error() string

type ErrUnsupportedEncryption added in v1.2.1

type ErrUnsupportedEncryption struct {
	Algorithm string
}

ErrUnsupportedEncryption is returned when the algorithm used is not supported.

func (ErrUnsupportedEncryption) Error added in v1.2.1

func (e ErrUnsupportedEncryption) Error() string

type ErrUnsupportedPrivateKeyFormat added in v1.2.1

type ErrUnsupportedPrivateKeyFormat struct {
	Format string
}

ErrUnsupportedPrivateKeyFormat is returned when the format used is not supported.

func (ErrUnsupportedPrivateKeyFormat) Error added in v1.2.1

type ErrUnsupportedPrivateKeyType added in v1.2.1

type ErrUnsupportedPrivateKeyType struct {
	Type string
}

ErrUnsupportedPrivateKeyType is returned when the type used is not supported.

func (ErrUnsupportedPrivateKeyType) Error added in v1.2.1

type ErrUnsupportedPublicKeyFormat added in v1.2.1

type ErrUnsupportedPublicKeyFormat struct {
	Format string
}

ErrUnsupportedPublicKeyFormat is returned when the format used is not supported.

func (ErrUnsupportedPublicKeyFormat) Error added in v1.2.1

type ErrUnsupportedPublicKeyType added in v1.2.1

type ErrUnsupportedPublicKeyType struct {
	Type string
}

ErrUnsupportedPublicKeyType is returned when the type used is not supported.

func (ErrUnsupportedPublicKeyType) Error added in v1.2.1

type ErrUnsupportedSignature added in v1.2.1

type ErrUnsupportedSignature struct {
	Algorithm string
}

ErrUnsupportedSignature is returned when the algorithm used is not supported.

func (ErrUnsupportedSignature) Error added in v1.2.1

func (e ErrUnsupportedSignature) Error() string

type KeyShare

type KeyShare struct {
	Name                 string           `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	PublicKey            []byte           `protobuf:"bytes,2,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"`
	PublicFormat         PublicKeyFormat  `` /* 126-byte string literal not displayed */
	PrivateKey           []byte           `protobuf:"bytes,4,opt,name=private_key,json=privateKey,proto3" json:"private_key,omitempty"`
	PrivateFormat        PrivateKeyFormat `` /* 130-byte string literal not displayed */
	Password             []byte           `protobuf:"bytes,6,opt,name=password,proto3" json:"password,omitempty"`
	XXX_NoUnkeyedLiteral struct{}         `json:"-"`
	XXX_unrecognized     []byte           `json:"-"`
	XXX_sizecache        int32            `json:"-"`
}

func (*KeyShare) Descriptor

func (*KeyShare) Descriptor() ([]byte, []int)

func (*KeyShare) GetName

func (m *KeyShare) GetName() string

func (*KeyShare) GetPassword

func (m *KeyShare) GetPassword() []byte

func (*KeyShare) GetPrivateFormat

func (m *KeyShare) GetPrivateFormat() PrivateKeyFormat

func (*KeyShare) GetPrivateKey

func (m *KeyShare) GetPrivateKey() []byte

func (*KeyShare) GetPublicFormat

func (m *KeyShare) GetPublicFormat() PublicKeyFormat

func (*KeyShare) GetPublicKey

func (m *KeyShare) GetPublicKey() []byte

func (*KeyShare) ProtoMessage

func (*KeyShare) ProtoMessage()

func (*KeyShare) Reset

func (m *KeyShare) Reset()

func (*KeyShare) String

func (m *KeyShare) String() string

func (*KeyShare) XXX_DiscardUnknown

func (m *KeyShare) XXX_DiscardUnknown()

func (*KeyShare) XXX_Marshal

func (m *KeyShare) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*KeyShare) XXX_Merge

func (m *KeyShare) XXX_Merge(src proto.Message)

func (*KeyShare) XXX_Size

func (m *KeyShare) XXX_Size() int

func (*KeyShare) XXX_Unmarshal

func (m *KeyShare) XXX_Unmarshal(b []byte) error

type KeyShareStore

type KeyShareStore map[string]*KeyShare

type PrivateKeyFormat

type PrivateKeyFormat int32
const (
	PrivateKeyFormat_UNKNOWN_PRIVATE_KEY_FORMAT PrivateKeyFormat = 0
	PrivateKeyFormat_PKCS1_PRIVATE              PrivateKeyFormat = 1
	PrivateKeyFormat_PKCS8                      PrivateKeyFormat = 2
)

func (PrivateKeyFormat) EnumDescriptor

func (PrivateKeyFormat) EnumDescriptor() ([]byte, []int)

func (PrivateKeyFormat) String

func (x PrivateKeyFormat) String() string

type PublicKeyFormat

type PublicKeyFormat int32
const (
	PublicKeyFormat_UNKNOWN_PUBLIC_KEY_FORMAT PublicKeyFormat = 0
	PublicKeyFormat_PKCS1_PUBLIC              PublicKeyFormat = 1
	PublicKeyFormat_PKIX                      PublicKeyFormat = 2
	PublicKeyFormat_X509                      PublicKeyFormat = 3
)

func (PublicKeyFormat) EnumDescriptor

func (PublicKeyFormat) EnumDescriptor() ([]byte, []int)

func (PublicKeyFormat) String

func (x PublicKeyFormat) String() string

type SignatureAlgorithm

type SignatureAlgorithm int32
const (
	SignatureAlgorithm_UNKNOWN_SIGNATURE SignatureAlgorithm = 0
	SignatureAlgorithm_SHA512WITHRSA     SignatureAlgorithm = 1
	SignatureAlgorithm_SHA512WITHRSA_PSS SignatureAlgorithm = 2
)

func (SignatureAlgorithm) EnumDescriptor

func (SignatureAlgorithm) EnumDescriptor() ([]byte, []int)

func (SignatureAlgorithm) String

func (x SignatureAlgorithm) String() string

Jump to

Keyboard shortcuts

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