Skip to content
A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption.
Go
Branch: master
Clone or download
Latest commit 1df12df Oct 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
3des.go Fix src over 16 bit encryption and decryption bug May 17, 2019
3des_test.go Added 3des May 5, 2019
LICENSE
README.md Fixed conflicts May 5, 2019
aes.go Fix src over 16 bit encryption and decryption bug May 17, 2019
aes_test.go Fix src over 16 bit encryption and decryption bug May 17, 2019
cbc.go Fix src over 16 bit encryption and decryption bug May 17, 2019
des.go Fix src over 16 bit encryption and decryption bug May 17, 2019
des_test.go Added DES encryptions Apr 28, 2019
ecb.go Fix src over 16 bit encryption and decryption bug May 17, 2019
go.mod Add md5 and sha1 func. Oct 16, 2019
go.sum Add md5 and sha1 func. Oct 16, 2019
key.go support java SHA1PRNG Aug 29, 2019
md5.go Add md5 and sha1 func. Oct 16, 2019
md5_test.go Add md5 and sha1 func. Oct 16, 2019
padding.go Fix src over 16 bit encryption and decryption bug May 17, 2019
sha.go Add md5 and sha1 func. Oct 16, 2019
sha_test.go

README.md

Openssl encryption

Build Status Coverage Status

A functions wrapping of OpenSSL library for symmetric and asymmetric encryption and decryption

Installation

The only requirement is the Go Programming Language

go get -u github.com/thinkoner/openssl

Usage

AES

The length of the key can be 16/24/32 characters (128/192/256 bits)

AES-ECB:

src := []byte("123456")
key := []byte("1234567890123456")
dst , _ := openssl.AesECBEncrypt(src, key, openssl.PKCS7_PADDING)
fmt.Printf(base64.StdEncoding.EncodeToString(dst))  // yXVUkR45PFz0UfpbDB8/ew==

dst , _ = openssl.AesECBDecrypt(dst, key, openssl.PKCS7_PADDING)
fmt.Println(string(dst)) // 123456

AES-CBC:

src := []byte("123456")
key := []byte("1234567890123456")
iv := []byte("1234567890123456")
dst , _ := openssl.AesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)
fmt.Println(base64.StdEncoding.EncodeToString(dst)) // 1jdzWuniG6UMtoa3T6uNLA==

dst , _ = openssl.AesCBCDecrypt(dst, key, iv, openssl.PKCS7_PADDING)
fmt.Println(string(dst)) // 123456

DES

The length of the key must be 8 characters (64 bits).

DES-ECB:

openssl.DesECBEncrypt(src, key, openssl.PKCS7_PADDING)
openssl.DesECBDecrypt(src, key, openssl.PKCS7_PADDING)

DES-CBC:

openssl.DesCBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)
openssl.DesCBCDecrypt(src, key, iv, openssl.PKCS7_PADDING)

3DES

The length of the key must be 24 characters (192 bits).

3DES-ECB:

openssl.Des3ECBEncrypt(src, key, openssl.PKCS7_PADDING)
openssl.Des3ECBDecrypt(src, key, openssl.PKCS7_PADDING)

3DES-CBC:

openssl.Des3CBCEncrypt(src, key, iv, openssl.PKCS7_PADDING)
openssl.Des3CBCDecrypt(src, key, iv, openssl.PKCS7_PADDING)

License

This project is licensed under the Apache 2.0 license.

Contact

If you have any issues or feature requests, please contact us. PR is welcomed.

You can’t perform that action at this time.