encrypt

package module
v0.0.0-...-fb908b2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2013 License: BSD-3-Clause Imports: 7 Imported by: 0

README

encrypt

Package encrypt provides encrypt and decrypt functions for byte blocks with AES.

From stack overflow: http://stackoverflow.com/questions/18817336/golang-encrypting-a-string-with-aes-and-base64

Documentation

Overview

Package encrypt provides encrypt and decrypt functions for byte blocks with AES.

From stack overflow: http://stackoverflow.com/questions/18817336/golang-encrypting-a-string-with-aes-and-base64

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64

func DecodeBase64(s string) []byte

func Decrypt

func Decrypt(key, text []byte) string

Decrypt with specified key (32 bytes)

Example
encrypted := "pLJGOMRo4IxI/wAiLe5dhFYCiwcCMCpa80JzTunHBYY3S3q2E3YhiShGmVOHx55NENjwzAaSmsjlhDlc7wHWQQ=="
text := "Two roads diverged in a yellow wood"
// 32 bytes
secretKey := []byte("1m!Cn25GW2frzDefg)^q2koE(4K2vIQX")
decrypt := Decrypt(secretKey, []byte(DecodeBase64(encrypted)))
fmt.Println(decrypt)
sha1 := Sha1([]byte(decrypt))
sha2 := Sha1([]byte(text))
fmt.Println("sha1:", sha1, "sha2:", sha2)
Output:

Two roads diverged in a yellow wood
sha1: 97d2ce306525e5036b6a39737d8ac415869f6e4c sha2: 97d2ce306525e5036b6a39737d8ac415869f6e4c

func EncodeBase64

func EncodeBase64(b []byte) string

func Encrypt

func Encrypt(key, text []byte) []byte

Encrypt with specified key (32 bytes)

Example
text := "Two roads diverged in a yellow wood"
// 32 bytes
secretKey := []byte("1m!Cn25GW2frzDefg)^q2koE(4K2vIQX")
encrypted := Encrypt(secretKey, []byte(text))
fmt.Println(EncodeBase64(encrypted))
fmt.Println("sha1:", Sha1([]byte(text)))
Output:

pLJGOMRo4IxI/wAiLe5dhFYCiwcCMCpa80JzTunHBYY3S3q2E3YhiShGmVOHx55NENjwzAaSmsjlhDlc7wHWQQ==
sha1: 97d2ce306525e5036b6a39737d8ac415869f6e4c

func Sha1

func Sha1(b []byte) string

Types

This section is empty.

Jump to

Keyboard shortcuts

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