You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.4 KiB
38 lines
1.4 KiB
package salty
|
|
|
|
import (
|
|
"github.com/keys-pub/keys"
|
|
"github.com/keys-pub/keys/saltpack"
|
|
)
|
|
|
|
// Encrypt encrypts the `input` using the Private Key `key` to the Public Keys of the
|
|
// `recipients`. Armour serializing is used by default. The armour bytes are returned on
|
|
// success or nil bytes and an error on failure.
|
|
func Encrypt(key *keys.EdX25519Key, input []byte, recipients []string) ([]byte, error) {
|
|
ids := keys.NewIDSet()
|
|
for _, recipient := range recipients {
|
|
ids.Add(keys.ID(recipient))
|
|
}
|
|
|
|
return saltpack.Signcrypt(input, true, key, ids.IDs()...)
|
|
}
|
|
|
|
// Decrypt decrypts the `input` using the Private Key `key` and returns the unencrypted
|
|
// bytes and the sender's public key on success, or nill bytes and a nil sender on failure.
|
|
func Decrypt(key *keys.EdX25519Key, input []byte) ([]byte, *keys.EdX25519PublicKey, error) {
|
|
return saltpack.SigncryptOpen(input, true, saltpack.NewKeyring(key))
|
|
}
|
|
|
|
// Sign signs the `input` using the Private Key `key`
|
|
// Armour serializing is used by default. The armour bytes are returned on
|
|
// success or nil bytes and an error on failure.
|
|
func Sign(key *keys.EdX25519Key, input []byte) ([]byte, error) {
|
|
return saltpack.Sign(input, true, key)
|
|
}
|
|
|
|
// Verify verifies the `input` and returns the otput as well as the key
|
|
// used to sign the message on success, or nil bytes, an empty signer key
|
|
// and en error on failure.
|
|
func Verify(input []byte) ([]byte, keys.ID, error) {
|
|
return saltpack.Verify(input)
|
|
}
|
|
|