Documentation ¶
Index ¶
- Variables
- func CallAgent(addr string, req AgentReq, in io.Reader, out io.Writer)
- func Decode(data []byte, receiver PrivateKey, sender []byte) ([]byte, error)
- func DecodeString(data string, receiver PrivateKey, sender []byte) (string, error)
- func Encode(data []byte, sender PrivateKey, receivers ...[]byte) ([]byte, error)
- func EncodeString(data string, sender PrivateKey, receivers ...[]byte) (string, error)
- func IsAgentRunning(addr, version string) bool
- func IsPassphraseRight(addr string, prv PrivateKey) bool
- func New(conf Config) (piper.EncodeDecoder, error)
- func Version() string
- type AgentReq
- type AgentRes
- type AgentServer
- type Config
- type PrivateKey
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Base64Encoding = base64.RawURLEncoding
Functions ¶
func Decode ¶ added in v0.0.5
func Decode(data []byte, receiver PrivateKey, sender []byte) ([]byte, error)
func DecodeString ¶ added in v0.0.5
func DecodeString(data string, receiver PrivateKey, sender []byte) (string, error)
func Encode ¶ added in v0.0.5
func Encode(data []byte, sender PrivateKey, receivers ...[]byte) ([]byte, error)
func EncodeString ¶ added in v0.0.5
func EncodeString(data string, sender PrivateKey, receivers ...[]byte) (string, error)
func IsAgentRunning ¶ added in v0.1.0
func IsPassphraseRight ¶ added in v0.2.3
func IsPassphraseRight(addr string, prv PrivateKey) bool
func New ¶ added in v0.0.4
func New(conf Config) (piper.EncodeDecoder, error)
New data encoding flow:
data -> gzip -> encrypt -> base64
Example ¶
package main import ( "fmt" "os" "path/filepath" whisper "github.com/ysmood/whisper/lib" ) func main() { sender, senderPub := whisper.PrivateKey{read("id_ecdsa"), "test"}, read("id_ecdsa.pub") receiver01, receiver01Pub := whisper.PrivateKey{read("id_ecdsa01"), "test"}, read("id_ecdsa01.pub") receiver02, receiver02Pub := whisper.PrivateKey{read("id_ecdsa02"), "test"}, read("id_ecdsa02.pub") // Encrypt the message that can be decrypted by both receiver01 and receiver02. enc, _ := whisper.EncodeString("hello world!", sender, receiver01Pub, receiver02Pub) dec01, _ := whisper.DecodeString(enc, receiver01, senderPub) dec02, _ := whisper.DecodeString(enc, receiver02, senderPub) fmt.Println(dec01, dec02) } func read(path string) []byte { b, err := os.ReadFile(filepath.FromSlash("secure/test_data/" + path)) if err != nil { panic(err) } return b }
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 cli 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 { GzipLevel int Base64 bool Private PrivateKey Public []secure.KeyWithFilter }
type PrivateKey ¶ added in v0.0.5
Click to show internal directories.
Click to hide internal directories.