Exemplo n.º 1
0
func newEncryptionReader(privateKey *openssl.PrivateKey, input io.Reader) *EncryptionReader {
	tarFile := tar.NewReader(input)

	key := decryptKey(readNextEntry(tarFile), privateKey)
	iv := readNextEntry(tarFile)

	cipher, err := openssl.GetCipherByName("aes-256-cbc")
	if err != nil {
		log.Fatalln(err)
	}

	ctx, err := openssl.NewDecryptionCipherCtx(cipher, nil, key, iv)
	if err != nil {
		log.Fatalln(err)
	}

	return &EncryptionReader{rd: tarFile, ctx: ctx}
}
Exemplo n.º 2
0
func newEncryptionWriter(publicKey *openssl.PublicKey, output io.Writer) *EncryptionWriter {
	cipher, err := openssl.GetCipherByName("aes-256-cbc")
	if err != nil {
		log.Fatalln(err)
	}

	key := randomBytes(cipher.KeySize())
	iv := randomBytes(cipher.IVSize())
	ctx, err := openssl.NewEncryptionCipherCtx(cipher, nil, key, iv)
	if err != nil {
		log.Fatalln(err)
	}

	tarFile := tar.NewWriter(output)
	writer := &EncryptionWriter{wr: tarFile, ctx: ctx}
	writer.writeToTar("key", encryptKey(key, publicKey))
	writer.writeToTar("iv", iv)

	return writer
}