xcrypt

package module
v0.0.0-...-29740f6 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

Xcrypt

Introduction

Easy way to encrypt and decrypt strings using AES 128,192 or 256 with CBC.

The AES algorithm has a 128-bit block size, regardless of whether you key length is 256, 192 or 128 bits.When a symmetric cipher mode requires an IV, the length of the IV must be equal to the block size of the cipher. Hence, you must always use an IV of 128 bits (16 bytes) with AES. AES provides 128 bit, 192 bit and 256 bit of secret key size for encryption. Things to remember here is if you are selecting 128 bits for encryption, then the secret key must be of 16 bits long and 24 and 32 bits for 192 and 256 bits of key size

How to use it

Let's see an example:

import("github.com/XbyOrange/xcrypt")

Functions

EncryptCBC:

CBC mode is highly recommended and it requires IV to make each message unique

  • Generate a random IV and returns the encrypted(base64 encoded)
key := []byte("I'm a key")
ciphertext,err := xcrypt.EncryptCBC(key, "Plain text")
if err != nil{
	fmt.Println(err)
}
fmt.Printf("%s\n", ciphertext)

DecryptCBC:

  • Input: encrypted text(base64 encoded)
  • Output: decrypted text
key := []byte("I'm a key")
result, err := xcrypt.DecryptCBC(key, ciphertext)
if err != nil {
	fmt.Println(err)
}
fmt.Printf("%s\n", result)

How to import it

With dep
dep ensure -add github.com/XbyOrange/xcrypt
With go get
go get github.com/XbyOrange/xcrypt

Just that! You can import it in your fantastic Go program!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptCBC

func DecryptCBC(key []byte, encryptedText string) (string, error)

func EncryptCBC

func EncryptCBC(key []byte, plaintextString string) (string, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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