Documentation ¶
Index ¶
- Constants
- Variables
- func CallAgent(addr string, req AgentReq, in io.Reader, out io.Writer) error
- func ClearCache(addr string) error
- func Decode(data []byte, conf Config) ([]byte, error)
- func DecodeString(data string, conf Config) (string, error)
- func Encode(data []byte, conf Config) ([]byte, error)
- func EncodeString(data string, conf Config) (string, error)
- func IsAgentRunning(addr, version string) (bool, error)
- func IsPassphraseRight(addr string, prv PrivateKey) (bool, error)
- func New(conf Config) piper.EncodeDecoder
- type AgentReq
- type AgentRes
- type AgentServer
- type Config
- type Meta
- type MetaFlag
- type PrivateKey
- type PublicKey
- type Whisper
Examples ¶
Constants ¶
const ( APIVersion = "v0.3.6" FormatVersion = byte(3) )
Variables ¶
var ErrNoPrivateKey = errors.New("no private key")
var ErrPubKeyNotFound = errors.New("public key not found")
var ErrPubPrvNotMatch = errors.New("public and private key not match")
var ErrVersionMismatch = errors.New("whisper file format version mismatch")
var ErrWrongPublicKey = errors.New("the public key from option -a doesn't belong to the private key")
Functions ¶
func ClearCache ¶ added in v0.3.2
func IsAgentRunning ¶ added in v0.1.0
func IsPassphraseRight ¶ added in v0.2.3
func IsPassphraseRight(addr string, prv PrivateKey) (bool, error)
func New ¶ added in v0.0.4
func New(conf Config) piper.EncodeDecoder
New encoder and decoder pair. The encoding process:
data -> gzip -> cipher -> sign -> meta
The sign, gzip are optional.
Decoding is the reverse as the encoding. It will still decode the whole data even the signature check fails, it will return secure.ErrSignNotMatch error.
Example ¶
package main import ( "fmt" "os" "path/filepath" whisper "github.com/ysmood/whisper/lib" ) func main() { recipient01, recipient01Pub := keyPair("id_ecdsa01", "test") recipient02, recipient02Pub := keyPair("id_ecdsa02", "test") // Encrypt the message that can be decrypted by both recipient01 and recipient02. encrypted, _ := whisper.EncodeString("hello world!", whisper.Config{ Public: []whisper.PublicKey{recipient01Pub, recipient02Pub}, }) decrypted01, _ := whisper.DecodeString(encrypted, whisper.Config{Private: &recipient01}) decrypted02, _ := whisper.DecodeString(encrypted, whisper.Config{Private: &recipient02}) fmt.Println(decrypted01, decrypted02) } func keyPair(privateKeyName, passphrase string) (whisper.PrivateKey, whisper.PublicKey) { prv, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + privateKeyName)) if err != nil { panic(err) } pub, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + privateKeyName + ".pub")) if err != nil { panic(err) } return whisper.PrivateKey{prv, passphrase}, whisper.PublicKey{Data: pub} }
Output: hello world! hello world!
Types ¶
type AgentServer ¶ added in v0.1.0
AgentServer is a tcp server that can be used to avoid inputting the passphrase every time. It will do the encryption and decryption for you, not the agent client. There's no way to get the passphrase from the tcp client, the only way to get the passphrase is to have root permission and dump the os memory. If the server restarts you have to send it to server again.
func NewAgentServer ¶ added in v0.1.0
func NewAgentServer() *AgentServer
func (*AgentServer) Handle ¶ added in v0.1.0
func (a *AgentServer) Handle(s io.ReadWriteCloser) error
func (*AgentServer) Listen ¶ added in v0.1.0
func (a *AgentServer) Listen(l net.Listener)
Serve start a http server to avoid inputting the passphrase every time.
func (*AgentServer) Serve ¶ added in v0.1.0
func (a *AgentServer) Serve(addr string)
Serve start a http server to avoid inputting the passphrase every time.
type Config ¶ added in v0.1.0
type Config struct { // Gzip compression level GzipLevel int // For data decryption and signature signing. Private *PrivateKey // For signature checking and meta data prefixing. Sign *PublicKey // For data encryption of different recipients Public []PublicKey }
func (Config) EncodeMeta ¶ added in v0.3.0
The meta format is:
[version][flags][sender][key num][key2 hash]...
"version" is the whisper file format version. "flags" about the encoding, such as if gzip, base64 are enabled or not. "sender" is the sender's public key [PublicKey.ID] and [PublicKey.Selector]. "key num" is the num of recipients. "key1 hash" is the hash of the first recipient's public key. "key2 hash" is the hash of the second recipient's public key. ...
type Meta ¶ added in v0.3.0
type Meta struct { Gzip bool Sign bool LongPubKeyHash bool Sender *PublicKey PubKeyHashList map[string]int }
type PrivateKey ¶ added in v0.0.5
type PublicKey ¶ added in v0.0.5
type PublicKey struct { Data []byte // A public ID for the public key, it can be a https url or github id. ID string // Uses to select the specific key in the URL file. // The line contains the Selector substring will be selected. Selector string }