Documentation ¶
Overview ¶
Copyright 2017 Mailgun Technologies Inc
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright 2017 Mailgun Technologies Inc ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
`secret` provides tools for encrypting and decrypting authenticated messages. See docs/secret.md for more details.
Index ¶
- Constants
- Variables
- func EncodedStringToKey(encodedKey string) (*[SecretKeyLength]byte, error)
- func KeySliceToArray(bytes []byte) (*[SecretKeyLength]byte, error)
- func KeyToEncodedString(keybytes *[SecretKeyLength]byte) string
- func NewKey() (*[SecretKeyLength]byte, error)
- func Open(e SealedData, secretKey *[SecretKeyLength]byte) ([]byte, error)
- func ReadKeyFromDisk(keypath string) (*[SecretKeyLength]byte, error)
- func SealedDataToString(sealedData SealedData) (string, error)
- type Config
- type SealedBytes
- type SealedData
- type SecretService
- type Service
Constants ¶
const NonceLength = 24 // length of nonce
const SecretKeyLength = 32 // lenght of secret key
Variables ¶
var RandomProvider random.RandomProvider
Functions ¶
func EncodedStringToKey ¶
func EncodedStringToKey(encodedKey string) (*[SecretKeyLength]byte, error)
EncodedStringToKey converts a base64-encoded string into key bytes.
func KeySliceToArray ¶
func KeySliceToArray(bytes []byte) (*[SecretKeyLength]byte, error)
func KeyToEncodedString ¶
func KeyToEncodedString(keybytes *[SecretKeyLength]byte) string
KeyToEncodedString converts bytes into a base64-encoded string
func NewKey ¶
func NewKey() (*[SecretKeyLength]byte, error)
NewKey returns a new key that can be used to encrypt and decrypt messages.
func Open ¶
func Open(e SealedData, secretKey *[SecretKeyLength]byte) ([]byte, error)
Open authenticates the ciphertext and if valid, decrypts and returns plaintext. Allows passing in a key and useful for one off opening purposes, otherwise create a secret.Service to open multiple times.
func ReadKeyFromDisk ¶
func ReadKeyFromDisk(keypath string) (*[SecretKeyLength]byte, error)
func SealedDataToString ¶
func SealedDataToString(sealedData SealedData) (string, error)
Given SealedData returns equivalent URL safe base64 encoded string.
Types ¶
type Config ¶
type Config struct { KeyPath string KeyBytes *[SecretKeyLength]byte EmitStats bool // toggle emitting metrics or not StatsdHost string // hostname of statsd server StatsdPort int // port of statsd server StatsdPrefix string // prefix to prepend to metrics }
Config is used to configure a secret service. It contains either the key path or key bytes to use.
type SealedBytes ¶
SealedBytes contains the ciphertext and nonce for a sealed message.
func (*SealedBytes) CiphertextBytes ¶
func (s *SealedBytes) CiphertextBytes() []byte
func (*SealedBytes) CiphertextHex ¶
func (s *SealedBytes) CiphertextHex() string
func (*SealedBytes) NonceBytes ¶
func (s *SealedBytes) NonceBytes() []byte
func (*SealedBytes) NonceHex ¶
func (s *SealedBytes) NonceHex() string
type SealedData ¶
type SealedData interface { CiphertextBytes() []byte CiphertextHex() string NonceBytes() []byte NonceHex() string }
SealedData respresents an encrypted and authenticated message.
func Seal ¶
func Seal(value []byte, secretKey *[SecretKeyLength]byte) (SealedData, error)
Seal takes plaintext and a key and returns encrypted and authenticated ciphertext. Allows passing in a key and useful for one off sealing purposes, otherwise create a secret.Service to seal multiple times.
func StringToSealedData ¶
func StringToSealedData(encodedBytes string) (SealedData, error)
Given a URL safe base64 encoded string, returns SealedData.
type SecretService ¶
type SecretService interface { // Seal takes a plaintext message and returns an encrypted and authenticated ciphertext. Seal([]byte) (SealedData, error) // Open authenticates the ciphertext and, if it is valid, decrypts and returns plaintext. Open(SealedData) ([]byte, error) }
SecretSevice is an interface for encrypting/decrypting and authenticating messages.
func New ¶
func New(config *Config) (SecretService, error)
New returns a new Service. Config can not be nil.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
A Service can be used to seal/open (encrypt/decrypt and authenticate) messages.