openssl

package module
v0.0.0-...-9a0dc39 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

README

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/forgoer/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.

Documentation

Index

Constants

View Source
const PKCS5_PADDING = "PKCS5"
View Source
const PKCS7_PADDING = "PKCS7"
View Source
const ZEROS_PADDING = "ZEROS"

Variables

This section is empty.

Functions

func AesCBCDecrypt

func AesCBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

AesCBCDecrypt

func AesCBCEncrypt

func AesCBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

AesCBCEncrypt

func AesECBDecrypt

func AesECBDecrypt(src, key []byte, padding string) ([]byte, error)

AesECBDecrypt

func AesECBEncrypt

func AesECBEncrypt(src, key []byte, padding string) ([]byte, error)

AesECBEncrypt

func CBCDecrypt

func CBCDecrypt(block cipher.Block, src, iv []byte, padding string) ([]byte, error)

CBCDecrypt

func CBCEncrypt

func CBCEncrypt(block cipher.Block, src, iv []byte, padding string) ([]byte, error)

CBCEncrypt

func Des3CBCDecrypt

func Des3CBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

Des3CBCDecrypt

func Des3CBCEncrypt

func Des3CBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

Des3CBCEncrypt

func Des3ECBDecrypt

func Des3ECBDecrypt(src, key []byte, padding string) ([]byte, error)

Des3ECBDecrypt

func Des3ECBEncrypt

func Des3ECBEncrypt(src, key []byte, padding string) ([]byte, error)

Des3ECBEncrypt

func DesCBCDecrypt

func DesCBCDecrypt(src, key, iv []byte, padding string) ([]byte, error)

DesCBCDecrypt

func DesCBCEncrypt

func DesCBCEncrypt(src, key, iv []byte, padding string) ([]byte, error)

DesCBCEncrypt

func DesECBDecrypt

func DesECBDecrypt(src, key []byte, padding string) ([]byte, error)

DesECBDecrypt

func DesECBEncrypt

func DesECBEncrypt(src, key []byte, padding string) ([]byte, error)

DesECBEncrypt

func ECBDecrypt

func ECBDecrypt(block cipher.Block, src []byte, padding string) ([]byte, error)

func ECBEncrypt

func ECBEncrypt(block cipher.Block, src []byte, padding string) ([]byte, error)

func KeyGenerator

func KeyGenerator(src []byte, blockSize int) []byte

func Md5

func Md5(str string, rawOutput ...bool) string

Md5 Calculate the md5 hash of a string If the optional rawOutput is set to true, then the md5 digest is instead returned in raw binary format with a length of 16.

func NewECBDecrypter

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

NewECBDecrypter returns a BlockMode which decrypts in electronic code book mode, using the given Block.

func NewECBEncrypter

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

NewECBEncrypter returns a BlockMode which encrypts in electronic code book mode, using the given Block.

func PKCS5Padding

func PKCS5Padding(src []byte, blockSize int) []byte

func PKCS5Unpadding

func PKCS5Unpadding(src []byte) []byte

func PKCS7Padding

func PKCS7Padding(src []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(src []byte) []byte

func Padding

func Padding(padding string, src []byte, blockSize int) []byte

func SHA1

func SHA1(data []byte) []byte

func Sha1

func Sha1(str string) string

Sha1 Calculate the sha1 hash of a string

func UnPadding

func UnPadding(padding string, src []byte) []byte

func ZerosPadding

func ZerosPadding(src []byte, blockSize int) []byte

func ZerosUnPadding

func ZerosUnPadding(src []byte) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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