gocrypto

package
v0.0.0-...-34af52f Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ECDSAPrivateKey

type ECDSAPrivateKey struct {
	KeyBase
	// contains filtered or unexported fields
}

ECDSAPrivateKey implements the `ifcrypto.KeyPair` interface for a `*rsa.PrivateKey`.

func NewECDSAPrivateKey

func NewECDSAPrivateKey(id string, bits int, usage ...ifcrypto.KeyUsage) (*ECDSAPrivateKey, error)

NewECDSAPrivateKey generates a new `ECDSAPrivateKey` using the `rand.Reader` as entropy.

func NewECDSAPrivateKeyFromKey

func NewECDSAPrivateKeyFromKey(
	id string,
	key *ecdsa.PrivateKey,
	usage ...ifcrypto.KeyUsage,
) *ECDSAPrivateKey

NewECDSAPrivateKeyFromKey creates a new `ECDSAPrivateKey`

The public key portion derives the same usage as the private key

func NewECDSAPrivateKeyFromPEM

func NewECDSAPrivateKeyFromPEM(
	block pem.Block,
	id string,
	usage ...ifcrypto.KeyUsage,
) (*ECDSAPrivateKey, error)

NewECDSAPrivateKeyFromPEM initializes a new `*ecdsa.PrivateKey` from the underlying _PEM_ block.

func (*ECDSAPrivateKey) GetKey

func (r *ECDSAPrivateKey) GetKey() interface{}

GetKey gets the underlying key, if any.

Some keys are remote and not possible to fetch. In such situations the function returns a remote id, most often the same as GetID() returns.

func (*ECDSAPrivateKey) GetPublic

func (r *ECDSAPrivateKey) GetPublic() ifcrypto.PublicKey

GetPublic returns the public portion of the key

func (*ECDSAPrivateKey) IsPrivate

func (r *ECDSAPrivateKey) IsPrivate() bool

IsPrivate returns `true` if this is a `KeyType` other than `KeyTypeSymmetric` and is a private key.

If `KeyTypeSymmetric` it will return `true` since all symmetric keys are considered as private.

func (*ECDSAPrivateKey) IsRemoteKey

func (r *ECDSAPrivateKey) IsRemoteKey() bool

IsRemoteKey returns `true` if the key is not present in current process memory.

Typically hardware units or remote services will not reveal their private key. In such case, this method returns `true`. If present in memory such as a `*rsa.PrivateKey` it returns `false`.

func (*ECDSAPrivateKey) IsSymmetric

func (r *ECDSAPrivateKey) IsSymmetric() bool

IsSymmetric returns `true` if this is a `KeyTypeSymmetric`

This is a convenience function instead of `GetKeyType`.

func (*ECDSAPrivateKey) PEMWrite

func (r *ECDSAPrivateKey) PEMWrite(w io.Writer, public bool) error

PEMWrite will write the key onto _w_.

If private key, and _public_ is `true`, it will in addition write the public portion as well.

func (*ECDSAPrivateKey) Sign

func (r *ECDSAPrivateKey) Sign(
	rand io.Reader,
	digest []byte,
	opts crypto.SignerOpts,
) ([]byte, error)

Sign implements the `crypto.Signer` _interface_. The _opts_ arguments is not used.

type ECDSAPublicKey

type ECDSAPublicKey struct {
	KeyBase
	// contains filtered or unexported fields
}

ECDSAPublicKey implements the `ifcrypto.PublicKey` interface for `*rsa.PublicKey`

func NewECDSAPublicKeyFromKey

func NewECDSAPublicKeyFromKey(
	id string,
	key *ecdsa.PublicKey,
	usage ...ifcrypto.KeyUsage,
) *ECDSAPublicKey

NewECDSAPublicKeyFromKey creates a instance based on a existing public key.

func NewECDSAPublicKeyFromPEM

func NewECDSAPublicKeyFromPEM(
	block pem.Block,
	id string,
	usage ...ifcrypto.KeyUsage,
) (*ECDSAPublicKey, error)

NewECDSAPublicKeyFromPEM initializes a new `*ecdsa.PublicKey` from the underlying _PEM_ block.

func (*ECDSAPublicKey) GetKey

func (r *ECDSAPublicKey) GetKey() interface{}

GetKey gets the underlying key, if any.

Some keys are remote and not possible to fetch. In such situations the function returns a remote id, most often the same as GetID() returns.

func (*ECDSAPublicKey) IsPrivate

func (r *ECDSAPublicKey) IsPrivate() bool

IsPrivate returns `true` if this is a `KeyType` other than `KeyTypeSymmetric` and is a private key.

If `KeyTypeSymmetric` it will return `true` since all symmetric keys are considered as private.

func (*ECDSAPublicKey) IsRemoteKey

func (r *ECDSAPublicKey) IsRemoteKey() bool

IsRemoteKey returns `true` if the key is not present in current process memory.

Typically hardware units or remote services will not reveal their private key. In such case, this method returns `true`. If present in memory such as a `*rsa.PrivateKey` it returns `false`.

func (*ECDSAPublicKey) IsSymmetric

func (r *ECDSAPublicKey) IsSymmetric() bool

IsSymmetric returns `true` if this is a `KeyTypeSymmetric`

This is a convenience function instead of `GetKeyType`.

func (*ECDSAPublicKey) PEMWrite

func (r *ECDSAPublicKey) PEMWrite(w io.Writer, public bool) error

PEMWrite will write the key onto _w_.

Since this is a public key, it will ignore the _public_ parameter.

type GoDigester

type GoDigester int

func NewDigester

func NewDigester() GoDigester

func (GoDigester) Digest

func (d GoDigester) Digest(key, msg []byte, h ...ifcrypto.HashAlgorithm) ([]byte, error)

Digest implements the `ifcrypto.Digester` interface.

type KeyBase

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

KeyBase implements most of the `ifcrypto.Key` interface.

This is used to derive from and implement the key specific functions.

func (*KeyBase) CanSign

func (b *KeyBase) CanSign(alg ifcrypto.SignAlgorithm) bool

CanSign checks if the current _Key_ may participate in _alg_ `SignAlgorithm` to do sign operations with.

func (*KeyBase) CanVerify

func (b *KeyBase) CanVerify(alg ifcrypto.SignAlgorithm) bool

CanVerify checks if the current _Key_ may participate in _alg_ `SignAlgorithm` to do verify on

func (*KeyBase) GetID

func (b *KeyBase) GetID() string

GetID returns a id of the key.

This is always specific of the backing _KMS_ system. For example, in _AWS_ this is a _ARN_ to a key in the _KMS_.

func (*KeyBase) GetKeySize

func (b *KeyBase) GetKeySize() int

GetKeySize returns the number of bits of the key

func (*KeyBase) GetKeyType

func (b *KeyBase) GetKeyType() ifcrypto.KeyType

GetKeyType returns this keys `KeyType`.

func (*KeyBase) GetKeyUsage

func (b *KeyBase) GetKeyUsage() []ifcrypto.KeyUsage

GetKeyUsage gets the keys usage. Some keys may have multiple usages.

func (*KeyBase) GetSupportedChiphers

func (b *KeyBase) GetSupportedChiphers() []ifcrypto.Chipher

GetSupportedChiphers returns all the chipers that the key be used with.

func (*KeyBase) HasUsage

func (b *KeyBase) HasUsage(u ifcrypto.KeyUsage) bool

HasUsage checks if the _b_ do have the _u_ `ifcrypto.KeyUsage` support.

type RSAPrivateKey

type RSAPrivateKey struct {
	KeyBase
	// contains filtered or unexported fields
}

RSAPrivateKey implements the `ifcrypto.KeyPair` interface for a `*rsa.PrivateKey`.

func NewRSAPrivateKey

func NewRSAPrivateKey(id string, bits int, usage ...ifcrypto.KeyUsage) (*RSAPrivateKey, error)

NewRSAPrivateKey generates a new `RSAPrivateKey` using the `rand.Reader` as entropy.

func NewRSAPrivateKeyFromKey

func NewRSAPrivateKeyFromKey(
	id string,
	key *rsa.PrivateKey,
	usage ...ifcrypto.KeyUsage,
) *RSAPrivateKey

NewRSAPrivateKeyFromKey creates a new `RSAPrivateKey`

The public key portion derives the same usage as the private key

func NewRSAPrivateKeyFromPEM

func NewRSAPrivateKeyFromPEM(
	block pem.Block,
	id string,
	usage ...ifcrypto.KeyUsage,
) (*RSAPrivateKey, error)

NewRSAPrivateKeyFromPEM initializes a new `*rsa.PrivateKey` from the underlying _PEM_ block.

func (*RSAPrivateKey) Decrypt

func (r *RSAPrivateKey) Decrypt(
	rand io.Reader,
	msg []byte,
	opts crypto.DecrypterOpts,
) (plaintext []byte, err error)

Decrypt implements the `crypto.Decrypter` _interface_. If opts is `nil` or of type `*PKCS1v15DecryptOptions` then _PKCS #1 v1.5_ decryption is performed. Otherwise opts must have type `*OAEPOptions` and _OAEP_ decryption is done.

func (*RSAPrivateKey) GetKey

func (r *RSAPrivateKey) GetKey() interface{}

GetKey gets the underlying key, if any.

Some keys are remote and not possible to fetch. In such situations the function returns a remote id, most often the same as GetID() returns.

func (*RSAPrivateKey) GetPublic

func (r *RSAPrivateKey) GetPublic() ifcrypto.PublicKey

GetPublic returns the public portion of the key

func (*RSAPrivateKey) IsPrivate

func (r *RSAPrivateKey) IsPrivate() bool

IsPrivate returns `true` if this is a `KeyType` other than `KeyTypeSymmetric` and is a private key.

If `KeyTypeSymmetric` it will return `true` since all symmetric keys are considered as private.

func (*RSAPrivateKey) IsRemoteKey

func (r *RSAPrivateKey) IsRemoteKey() bool

IsRemoteKey returns `true` if the key is not present in current process memory.

Typically hardware units or remote services will not reveal their private key. In such case, this method returns `true`. If present in memory such as a `*rsa.PrivateKey` it returns `false`.

func (*RSAPrivateKey) IsSymmetric

func (r *RSAPrivateKey) IsSymmetric() bool

IsSymmetric returns `true` if this is a `KeyTypeSymmetric`

This is a convenience function instead of `GetKeyType`.

func (*RSAPrivateKey) PEMWrite

func (r *RSAPrivateKey) PEMWrite(w io.Writer, public bool) error

PEMWrite will write the key onto _w_.

If private key, and _public_ is `true`, it will in addition write the public portion as well.

func (*RSAPrivateKey) Sign

func (r *RSAPrivateKey) Sign(
	rand io.Reader,
	digest []byte,
	opts crypto.SignerOpts,
) ([]byte, error)

Sign implements the `crypto.Signer` _interface_.If opts is a *PSSOptions then the PSS algorithm will be used, otherwise PKCS #1 v1.5 will be used.

type RSAPublicKey

type RSAPublicKey struct {
	KeyBase
	// contains filtered or unexported fields
}

RSAPublicKey implements the `ifcrypto.PublicKey` interface for `*rsa.PublicKey`

func NewRSAPublicKeyFromKey

func NewRSAPublicKeyFromKey(
	id string,
	key *rsa.PublicKey,
	usage ...ifcrypto.KeyUsage,
) *RSAPublicKey

NewRSAPublicKeyFromKey creates a instance based on a existing public key.

func NewRSAPublicKeyFromPEM

func NewRSAPublicKeyFromPEM(
	block pem.Block,
	id string,
	usage ...ifcrypto.KeyUsage,
) (*RSAPublicKey, error)

NewRSAPublicKeyFromPEM initializes a new `*rsa.PublicKey` from the underlying _PEM_ block.

func (*RSAPublicKey) GetKey

func (r *RSAPublicKey) GetKey() interface{}

GetKey gets the underlying key, if any.

Some keys are remote and not possible to fetch. In such situations the function returns a remote id, most often the same as GetID() returns.

func (*RSAPublicKey) IsPrivate

func (r *RSAPublicKey) IsPrivate() bool

IsPrivate returns `true` if this is a `KeyType` other than `KeyTypeSymmetric` and is a private key.

If `KeyTypeSymmetric` it will return `true` since all symmetric keys are considered as private.

func (*RSAPublicKey) IsRemoteKey

func (r *RSAPublicKey) IsRemoteKey() bool

IsRemoteKey returns `true` if the key is not present in current process memory.

Typically hardware units or remote services will not reveal their private key. In such case, this method returns `true`. If present in memory such as a `*rsa.PrivateKey` it returns `false`.

func (*RSAPublicKey) IsSymmetric

func (r *RSAPublicKey) IsSymmetric() bool

IsSymmetric returns `true` if this is a `KeyTypeSymmetric`

This is a convenience function instead of `GetKeyType`.

func (*RSAPublicKey) PEMWrite

func (r *RSAPublicKey) PEMWrite(w io.Writer, public bool) error

PEMWrite will write the key onto _w_.

Since this is a public key, it will ignore the _public_ parameter.

Jump to

Keyboard shortcuts

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