symmetric.go
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
	if len(secret) != secretLen {
		PanicSanity(Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
	}
	nonce := CRandBytes(nonceLen)
	nonceArr := [nonceLen]byte{}
	copy(nonceArr[:], nonce)
	secretArr := [secretLen]byte{}
	copy(secretArr[:], secret)
	ciphertext = make([]byte, nonceLen+secretbox.Overhead+len(plaintext))
	copy(ciphertext, nonce)
	secretbox.Seal(ciphertext[nonceLen:nonceLen], plaintext, &nonceArr, &secretArr)
	return ciphertext
}
func EncryptSymmetric(plaintext []byte, secret []byte) (ciphertext []byte) {
	if len(secret) != secretLen {
		PanicSanity(Fmt("Secret must be 32 bytes long, got len %v", len(secret)))
	}
	nonce := CRandBytes(nonceLen)
	nonceArr := [nonceLen]byte{}
	copy(nonceArr[:], nonce)
	secretArr := [secretLen]byte{}
	copy(secretArr[:], secret)
	ciphertext = make([]byte, nonceLen+secretbox.Overhead+len(plaintext))
	copy(ciphertext, nonce)
	secretbox.Seal(ciphertext[nonceLen:nonceLen], plaintext, &nonceArr, &secretArr)
	return ciphertext
}
func EncryptSymmetric ( plaintext [ ] byte , secret [ ] byte ) ( ciphertext [ ] byte ) { if len ( secret ) != secretLen { PanicSanity ( Fmt ( " " , len ( secret ) ) ) } nonce := CRandBytes ( nonceLen ) nonceArr := [ nonceLen ] byte { } copy ( nonceArr [ : ] , nonce ) secretArr := [ secretLen ] byte { } copy ( secretArr [ : ] , secret ) ciphertext = make ( [ ] byte , nonceLen + secretbox . Overhead + len ( plaintext ) ) copy ( ciphertext , nonce ) secretbox . Seal ( ciphertext [ nonceLen : nonceLen ] , plaintext , & nonceArr , & secretArr ) return ciphertext }
// secret must be 32 bytes long. Use something like Sha256(Bcrypt(passphrase))
// The ciphertext is (secretbox.Overhead + 24) bytes longer than the plaintext.
// NOTE: call crypto.MixEntropy() first.
secret must be 32 bytes long . Use something like Sha256 ( Bcrypt ( passphrase )) The ciphertext is ( secretbox . Overhead + 24 ) bytes longer than the plaintext . NOTE : call crypto . MixEntropy () first .