encrypt

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2015 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package encrypt implements a encrypt tool with fix salt and random salt.

Algorithm:

Give message and fix salt, return Hash(msg, Hash(salt + randSalt)) as result.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(hash hash.Hash, msg, salt []byte) ([]byte, []byte, error)

Encode a message with fixed salt, return the encoded message and random salt

func Hash

func Hash(hashNew func() hash.Hash, key, data []byte, tohex bool) []byte

func MD5 added in v0.2.3

func MD5(key, data []byte, tohex bool) []byte

func SHA1 added in v0.2.3

func SHA1(key, data []byte, tohex bool) []byte

func SHA256 added in v0.2.3

func SHA256(key, data []byte, tohex bool) []byte

func SHA512 added in v0.2.3

func SHA512(key, data []byte, tohex bool) []byte

func SaltEncode

func SaltEncode(hash hash.Hash, msg, fixed, rand []byte) []byte

SaltEncode encode the message with a fixed salt and a random salt, typically used to verify

Example
package main

import (
	"fmt"

	"github.com/cosiner/gohper/crypto/encrypt"
)

func main() {
	password := []byte("abcdefg")
	salt := []byte("123456")
	enc, randSalt, _ := encrypt.Encode(nil, password, salt)

	if encrypt.Verify(nil, password, salt, randSalt, enc) {
		fmt.Println("Password Match")
	} else {
		fmt.Println("Password don't match")
	}
}
Output:

Password Match

func Verify

func Verify(hash hash.Hash, msg, salt, randSalt, pass []byte) bool

Verify will encode msg, salt, randSalt, then compare it with encoded password, return true if equal, else false

Types

This section is empty.

Jump to

Keyboard shortcuts

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