1
0
Fork 0
mirror of https://github.com/Luzifer/go-openssl.git synced 2024-12-20 19:01:18 +00:00
go-openssl is a small library wrapping the crypto/aes functions in a way the output is compatible to OpenSSL
Find a file
Knut Ahlers ebc0cd6f3e
Fix: v2 versions require another go-modules name
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-09-18 15:21:09 +02:00
.travis.yml Add benchmarks 2018-09-11 12:12:43 +02:00
examples_test.go Adhere to example name conventions 2017-04-04 23:53:27 +02:00
go.mod Fix: v2 versions require another go-modules name 2018-09-18 15:21:09 +02:00
History.md prepare release v2.0.1 2018-09-18 15:10:25 +02:00
LICENSE Add LICENSE 2018-06-04 12:40:06 +02:00
openssl.go Fix some linter warnings 2018-09-11 12:16:18 +02:00
openssl_test.go Add benchmarks 2018-09-11 12:12:43 +02:00
README.md Adjust README 2018-09-11 11:43:54 +02:00

Go Report Card

Luzifer / go-openssl

go-openssl is a small library wrapping the crypto/aes functions in a way the output is compatible to OpenSSL / CryptoJS. 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.

OpenSSL 1.1.0c compatibility

Starting with v2.0.0 go-openssl generates the encryption keys using sha256sum algorithm. This is the default introduced in OpenSSL 1.1.0c. When encrypting data you can choose which digest method to use and therefore also continue to use md5sum. When decrypting OpenSSL encrypted data md5sum, sha1sum and sha256sum are supported.

Installation

go get github.com/Luzifer/go-openssl

Usage example

The usage is quite simple as you don't need any special knowledge about OpenSSL and/or AES256:

Encrypt

import (
  "fmt"
  "github.com/Luzifer/go-openssl"
)

func main() {
  plaintext := "Hello World!"
  passphrase := "z4yH36a6zerhfE5427ZV"

  o := openssl.New()

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

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

Decrypt

import (
  "fmt"
  "github.com/Luzifer/go-openssl"
)

func main() {
  opensslEncrypted := "U2FsdGVkX19ZM5qQJGe/d5A/4pccgH+arBGTp+QnWPU="
  passphrase := "z4yH36a6zerhfE5427ZV"

  o := openssl.New()

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

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

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.