Documentation
¶
Index ¶
- Variables
- type Algorithm
- type Entry
- type Key
- type Keystore
- func (ks *Keystore) Aliases() []string
- func (ks *Keystore) ContainsAlias(a string) (bool, error)
- func (ks *Keystore) Delete(a string, passphrase []byte) error
- func (ks *Keystore) GetKey(a string, passphrase []byte) (Key, error)
- func (ks *Keystore) GetUnlocked(alias string) (Key, error)
- func (ks *Keystore) Lock(alias string) error
- func (ks *Keystore) SetKey(a string, k Key, passphrase []byte) error
- func (ks *Keystore) Unlock(alias string, passphrase []byte, timeout time.Duration) error
- type MemoryProvider
- func (p *MemoryProvider) Aliases() []string
- func (p *MemoryProvider) Clear() error
- func (p *MemoryProvider) ContainsAlias(a string) (bool, error)
- func (p *MemoryProvider) Delete(a string) error
- func (p *MemoryProvider) GetKey(a string, passphrase []byte) (Key, error)
- func (p *MemoryProvider) SetKey(a string, key Key, passphrase []byte) error
- type PrivateKey
- type Provider
- type PublicKey
- type Signature
Constants ¶
This section is empty.
Variables ¶
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) )
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") )
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 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 (*Keystore) ContainsAlias ¶
ContainsAlias checks if the given alias exists in this keystore.
func (*Keystore) GetKey ¶
GetKey returns the key associated with the given alias, using the given password to recover it.
func (*Keystore) GetUnlocked ¶
GetUnlocked returns a unlocked key
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
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