keystore

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2018 License: LGPL-3.0 Imports: 4 Imported by: 8

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultKS generate a default keystore
	DefaultKS = NewKeystore()

	// DefaultUnlockDuration default lock 300s
	DefaultUnlockDuration = time.Duration(300 * time.Second)

	// YearUnlockDuration lock 1 year time
	YearUnlockDuration = time.Duration(365 * 24 * 60 * 60 * time.Second)
)
View Source
var (
	// ErrUninitialized uninitialized provider error.
	ErrUninitialized = errors.New("uninitialized the provider")

	// ErrNotUnlocked key not unlocked
	ErrNotUnlocked = errors.New("key not unlocked")

	// ErrInvalidPassphrase invalid passphrase
	ErrInvalidPassphrase = errors.New("passphrase is invalid")
)
View Source
var (
	// ErrNeedAlias need alias
	ErrNeedAlias = errors.New("need alias")

	// ErrNotFound not find key
	ErrNotFound = errors.New("key not found")
)

Functions

This section is empty.

Types

type Algorithm added in v0.2.0

type Algorithm uint8

Algorithm type alias

const (
	// SECP256K1 a type of signer
	SECP256K1 Algorithm = 1

	// SCRYPT a type of encrypt
	SCRYPT Algorithm = 1 << 4
)

type Entry added in v0.2.0

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

Entry keeps in memory

type Key

type Key interface {

	// Algorithm returns the standard algorithm for this key. For
	// example, "ECDSA" would indicate that this key is a ECDSA key.
	Algorithm() Algorithm

	// Encoded returns the key in its primary encoding format, or null
	// if this key does not support encoding.
	Encoded() ([]byte, error)

	// Decode decode data to key
	Decode(data []byte) error

	// Clear clear key content
	Clear()
}

Key interface

type Keystore

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

Keystore class represents a storage facility for cryptographic keys

func NewKeystore

func NewKeystore() *Keystore

NewKeystore new

func (*Keystore) Aliases

func (ks *Keystore) Aliases() []string

Aliases lists all the alias names of this keystore.

func (*Keystore) ContainsAlias

func (ks *Keystore) ContainsAlias(a string) (bool, error)

ContainsAlias checks if the given alias exists in this keystore.

func (*Keystore) Delete

func (ks *Keystore) Delete(a string, passphrase []byte) error

Delete the entry identified by the given alias from this keystore.

func (*Keystore) GetKey

func (ks *Keystore) GetKey(a string, passphrase []byte) (Key, error)

GetKey returns the key associated with the given alias, using the given password to recover it.

func (*Keystore) GetUnlocked

func (ks *Keystore) GetUnlocked(alias string) (Key, error)

GetUnlocked returns a unlocked key

func (*Keystore) Lock added in v0.2.0

func (ks *Keystore) Lock(alias string) error

Lock lock key

func (*Keystore) SetKey

func (ks *Keystore) SetKey(a string, k Key, passphrase []byte) error

SetKey assigns the given key to the given alias, protecting it with the given passphrase.

func (*Keystore) Unlock

func (ks *Keystore) Unlock(alias string, passphrase []byte, timeout time.Duration) error

Unlock unlock key with ProtectionParameter

type MemoryProvider

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

MemoryProvider handle keystore with ecdsa

func NewMemoryProvider

func NewMemoryProvider(v float32, alg Algorithm) *MemoryProvider

NewMemoryProvider generate a provider with version

func (*MemoryProvider) Aliases

func (p *MemoryProvider) Aliases() []string

Aliases all entry in provider save

func (*MemoryProvider) Clear

func (p *MemoryProvider) Clear() error

Clear clear all entries in provider

func (*MemoryProvider) ContainsAlias

func (p *MemoryProvider) ContainsAlias(a string) (bool, error)

ContainsAlias check provider contains key

func (*MemoryProvider) Delete

func (p *MemoryProvider) Delete(a string) error

Delete remove key

func (*MemoryProvider) GetKey

func (p *MemoryProvider) GetKey(a string, passphrase []byte) (Key, error)

GetKey returns the key associated with the given alias, using the given password to recover it.

func (*MemoryProvider) SetKey

func (p *MemoryProvider) SetKey(a string, key Key, passphrase []byte) error

SetKey assigns the given key (that has already been protected) to the given alias.

type PrivateKey

type PrivateKey interface {

	// Algorithm returns the standard algorithm for this key. For
	// example, "ECDSA" would indicate that this key is a ECDSA key.
	Algorithm() Algorithm

	// Encoded returns the key in its primary encoding format, or null
	// if this key does not support encoding.
	Encoded() ([]byte, error)

	// Decode decode data to key
	Decode(data []byte) error

	// Clear clear key content
	Clear()

	// PublicKey returns publickey
	PublicKey() PublicKey
}

PrivateKey privatekey interface

type Provider

type Provider interface {

	// Aliases all alias in provider save
	Aliases() []string

	// SetKey assigns the given key (that has already been protected) to the given alias.
	SetKey(a string, key Key, passphrase []byte) error

	// GetKey returns the key associated with the given alias, using the given
	// password to recover it.
	GetKey(a string, passphrase []byte) (Key, error)

	// Delete remove key
	Delete(a string) error

	// ContainsAlias check provider contains key
	ContainsAlias(a string) (bool, error)

	// Clear all entries in provider
	Clear() error
}

Provider class represents a "provider" for the Security API, where a provider implements some or all parts of Security. Services that a provider may implement include: Algorithms Key generation, conversion, and management facilities (such as for algorithm-specific keys). Each provider has a name and a version number, and is configured in each runtime it is installed in.

type PublicKey

type PublicKey interface {

	// Algorithm returns the standard algorithm for this key. For
	// example, "ECDSA" would indicate that this key is a ECDSA key.
	Algorithm() Algorithm

	// Encoded returns the key in its primary encoding format, or null
	// if this key does not support encoding.
	Encoded() ([]byte, error)

	// Decode decode data to key
	Decode(data []byte) error

	// Clear clear key content
	Clear()
}

PublicKey publickey interface

type Signature

type Signature interface {

	// Algorithm returns the standard algorithm for this key.
	Algorithm() Algorithm

	// InitSign this object for signing. If this method is called
	// again with a different argument, it negates the effect
	// of this call.
	InitSign(privateKey PrivateKey) error

	// Sign returns the signature bytes of all the data input.
	// The format of the signature depends on the underlying
	// signature scheme.
	Sign(data []byte) (out []byte, err error)

	// RecoverPublic returns a public key, which is recoverd by data and signature
	RecoverPublic(data []byte, signature []byte) (PublicKey, error)

	// InitVerify initializes this object for verification. If this method is called
	// again with a different argument, it negates the effect
	// of this call.
	InitVerify(publicKey PublicKey) error

	// Verify the passed-in signature.
	//
	// <p>A call to this method resets this signature object to the state
	// it was in when previously initialized for verification via a
	// call to <code>initVerify(PublicKey)</code>. That is, the object is
	// reset and available to verify another signature from the identity
	// whose public key was specified in the call to <code>initVerify</code>.
	Verify(data []byte, signature []byte) (bool, error)
}

Signature interface of different signature algorithm

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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