Example #1
0
// Absolute Base64-encoded encryption function. The return ciphertext
// is a base64-encoded ciphertext.
func AbsEncrypt(key []byte, pt []byte) (ct []byte, err error) {
	rawkey, err := decodeKey(key)
	if err != nil {
		return
	}

	enc, err := symmetric.Encrypt(rawkey, pt)
	if err != nil {
		return
	}

	ct = trim(EncodeBase64(enc))
	return
}
Example #2
0
func encrypt(w http.ResponseWriter, upload *Upload) {
	key := hash.DeriveKey(upload.Password)
	if key == nil {
		serverError(w, "failed to generate key")
		return
	}

	out := key.Salt
	enc, err := symmetric.Encrypt(key.Key, upload.Data)
	if err != nil {
		serverError(w, "encryption failure: "+err.Error())
		return
	}
	out = append(out, enc...)
	w.Header().Add("content-type", "application/octet-stream")
	w.Header().Add("content-disposition", "attachment; filename="+upload.Name)
	w.Write(out)
}
Example #3
0
func Encrypt(key []byte, msg []byte) (ct []byte, err error) {
	h := hash.New(msg)
	pt := h.Digest()
	pt = append(pt, msg...)
	return symmetric.Encrypt(key, pt)
}