aes256cbc

package
v0.0.0-...-3bc3e56 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2015 License: MIT Imports: 8 Imported by: 0

README

forked from Luzifer / go-openssl

go-openssl is a small library wrapping the crypto/aes functions in a way the output is compatible to OpenSSL. For all encryption / decryption processes AES256 is used so this library will not be able to decrypt messages generated with other than openssl aes-256-cbc. If you're using CryptoJS to process the data you also need to use AES256 on that side.

Installation

go get github.com/Luzifer/go-openssl

Usage example

Check the test cases for the usage. They're quite simple as you don't need any special knowledge about OpenSSL and/or AES256.

Testing

To execute the tests for this library you need to be on a system having /bin/bash and openssl available as the compatibility of the output is tested directly against the openssl binary. The library itself should be usable on all operating systems supported by Go and crypto/aes.

Documentation

Overview

Package aes256cbc is a helper to generate OpenSSL compatible encryption with autmatic IV derivation and storage. As long as the key is known all data can also get decrypted using OpenSSL CLI. Code from http://dequeue.blogspot.de/2014/11/decrypting-something-encrypted-with.html

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(passphrase, encrypted []byte) ([]byte, error)

Decrypt decrypts a []byte that was encrypted using OpenSSL and AES-256-CBC.

func DecryptBase64

func DecryptBase64(passphrase, encryptedBase64 []byte) ([]byte, error)

DecryptBase64 decrypts a base64 encoded []byte that was encrypted using OpenSSL and AES-256-CBC.

func DecryptString

func DecryptString(passphrase, encryptedBase64String string) (string, error)

DecryptString decrypts a base64 encoded string that was encrypted using OpenSSL and AES-256-CBC.

Example
opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU="
passphrase := "z4yH36a6zerhfE5427ZV"

dec, err := DecryptString(passphrase, opensslEncrypted)
if err != nil {
	fmt.Printf("An error occurred: %s\n", err)
}

fmt.Printf("Decrypted text: %s\n", string(dec))
Output:

Decrypted text: hallowelt

func Encrypt

func Encrypt(passphrase, plaintext []byte) ([]byte, error)

Encrypt encrypts a []byte in a manner compatible to OpenSSL encryption functions using AES-256-CBC as encryption algorithm

func EncryptBase64

func EncryptBase64(passphrase, plaintext []byte) ([]byte, error)

EncryptBase64 encrypts a []byte in a manner compatible to OpenSSL encryption functions using AES-256-CBC as encryption algorithm and encode to base64 format.

func EncryptString

func EncryptString(passphrase, plaintextString string) (string, error)

EncryptString encrypts a string in a manner compatible to OpenSSL encryption functions using AES-256-CBC as encryption algorithm and encode to base64 format.

Example
plaintext := "Hello World!"
passphrase := "z4yH36a6zerhfE5427ZV"

enc, err := EncryptString(passphrase, plaintext)
if err != nil {
	fmt.Printf("An error occurred: %s\n", err)
}

fmt.Printf("Encrypted text: %s\n", string(enc))
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL