encrypt

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2015 License: MIT Imports: 3 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

View Source
var Hash = sha256.New

Hash is the hash function used for Encode and SaltEncode

View Source
var SaltSize = sha256.Size

SaltSize is the size of generated salt in bytes used in Encode

Functions

func Encode

func Encode(msg, salt []byte) ([]byte, []byte, error)

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

func SaltEncode

func SaltEncode(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(password, salt)

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

Password Match

func Verify

func Verify(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