1
0
Fork 0
mirror of https://github.com/Luzifer/go-openssl.git synced 2024-10-18 06:14:21 +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
2023-08-22 14:34:19 +02:00
.github/workflows Add automated code checks through Github Actions 2023-08-22 14:25:00 +02:00
.golangci.yml Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
examples_test.go Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
go.mod Add support for stream writer and reader (#26) 2023-08-22 14:11:14 +02:00
go.sum Add support for stream writer and reader (#26) 2023-08-22 14:11:14 +02:00
History.md prepare release v4.2.0 2023-08-22 14:34:19 +02:00
keys.go Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
keys_test.go Add pre-defined generators and compatibility tests for SHA384 and SHA512 2020-06-13 18:12:42 +02:00
LICENSE Add LICENSE 2018-06-04 12:40:06 +02:00
Makefile Add automated code checks through Github Actions 2023-08-22 14:25:00 +02:00
openssl.go Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
openssl_test.go Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
README.md Update documentation to use modules format 2020-06-13 18:50:55 +02:00
stream.go Fix linter errors, simplify tests 2023-08-22 14:13:51 +02:00
stream_test.go Add support for stream writer and reader (#26) 2023-08-22 14:11:14 +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.

Version support

For this library only the latest major version is supported. All prior major versions should no longer be used.

The versioning is following SemVer which means upgrading to a newer major version will break your code!

OpenSSL compatibility

1.1.0c

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.

1.1.1

Starting with v4.0.0 go-openssl is capable of using the PBKDF2 key derivation method for encryption. You can choose to use it by passing the corresponding CredsGenerator.

Installation

# Get the latest version
go get github.com/Luzifer/go-openssl/v4

Usage example

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

Encrypt

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

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

  o := openssl.New()

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

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

Decrypt

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

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

  o := openssl.New()

  dec, err := o.DecryptBytes(passphrase, []byte(opensslEncrypted), BytesToKeyMD5)
  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.