hashvalues

package module
Version: v0.0.0-...-cbce250 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2015 License: MIT Imports: 6 Imported by: 0

README

toomore/hashvalues

GoDoc

Simple way to hash key-value data by using url.Values.

Install

go get -v github.com/toomore/hashvalues

Example - Encode

import (
    "crypto/sha256"
    "fmt"

    "github.com/toomore/hashvalues"
)

var h = hashvalues.New([]byte("Toomore.net"), sha256.New)
h.Set("name", "Toomore")
h.Set("age", "30")
key, msg := h.Encode()
fmt.Printf("Key:[%s] Msg:[%s]", key, msg)

output:

Key:[aTMzslluGEzE-uNMoLtBC2vN6aDYGc8fIXJFi_oXPG4=] Msg:[YWdlPTMwJm5hbWU9VG9vbW9yZQ==]

Example - Decode

var hashkey = []byte("Toomore.net")
var hashedKey = "aTMzslluGEzE-uNMoLtBC2vN6aDYGc8fIXJFi_oXPG4="
var message  = "YWdlPTMwJm5hbWU9VG9vbW9yZQ=="
var h = hashvalues.New(hashkey, sha256.New)
if err := h.Decode(hashedKey, message); err == nil {
    t.Logf("O: %+v", h.Values)
} else {
    t.Log(err)
}

LICENSE

The MIT License (MIT)

Copyright © 2015 Toomore Chiang, http://toomore.net/ toomore0929@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package hashvalues is a simple wrapper for hmac data.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(value []byte) ([]byte, error)

Base64Decode decodes a cookie using base64.

func Base64Encode

func Base64Encode(value []byte) []byte

Base64Encode encodes a value using base64.

Types

type HashValues

type HashValues struct {
	Values url.Values
	// contains filtered or unexported fields
}

HashValues struct

func New

func New(hashkey []byte, hashfunc func() hash.Hash) *HashValues

New to new a HashValues.

Example
var h = New(hashkey, hashfunc)
h.Set("name", "Toomore")
h.Set("age", "30")
key, msg := h.Encode()
fmt.Printf("Key:[%s] Msg:[%s]", key, msg)
Output:

Key:[aTMzslluGEzE-uNMoLtBC2vN6aDYGc8fIXJFi_oXPG4=] Msg:[YWdlPTMwJm5hbWU9VG9vbW9yZQ==]

func (*HashValues) Add

func (h *HashValues) Add(key, value string)

Add to add a key-value.

func (*HashValues) Decode

func (h *HashValues) Decode(key, message []byte) error

Decode to decode a hmac key with message.

func (*HashValues) Del

func (h *HashValues) Del(key string)

Del to del a key.

func (*HashValues) Encode

func (h *HashValues) Encode() ([]byte, []byte)

Encode to encode all data.

func (*HashValues) Get

func (h *HashValues) Get(key string) string

Get to get a value of key.

func (*HashValues) Set

func (h *HashValues) Set(key, value string)

Set to set a key-value.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL