hmac

package
v0.0.0-...-82e7740 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Md5

func Md5(src, key []byte) ([]byte, error)

Md5 calculates the MD5 digest and returns the value as a byte[].

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Md5([]byte("goyy"), []byte("key"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

aa35a3db5523705942e0d117faf76ed5

func Md5Hex

func Md5Hex(src, key string) (string, error)

Md5Hex calculates the MD5 digest and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Md5Hex("goyy", "key")
	fmt.Println(dst)

}
Output:

aa35a3db5523705942e0d117faf76ed5

func Md5Sum

func Md5Sum(src, key, sum []byte) ([]byte, error)

Md5Sum calculates the MD5 digest to sum and returns the resulting slice.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Md5Sum([]byte("goyy"), []byte("key"), []byte("goyy:"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

676f79793aaa35a3db5523705942e0d117faf76ed5

func Md5SumHex

func Md5SumHex(src, key, sum string) (string, error)

Md5SumHex calculates the MD5 digest to sum and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Md5SumHex("goyy", "key", "goyy:")
	fmt.Println(dst)

}
Output:

676f79793aaa35a3db5523705942e0d117faf76ed5

func Sha1

func Sha1(src, key []byte) ([]byte, error)

Sha1 calculates the SHA-1 digest and returns the value as a byte[].

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha1([]byte("goyy"), []byte("key"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

221f50c7d0d8f13e160be5660a1a27d5bb18861c

func Sha1Hex

func Sha1Hex(src, key string) (string, error)

Sha1Hex calculates the SHA-1 digest and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha1Hex("goyy", "key")
	fmt.Println(dst)

}
Output:

221f50c7d0d8f13e160be5660a1a27d5bb18861c

func Sha1Sum

func Sha1Sum(src, key, sum []byte) ([]byte, error)

Sha1Sum calculates the SHA-1 digest to sum and returns the resulting slice.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha1Sum([]byte("goyy"), []byte("key"), []byte("goyy:"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

676f79793a221f50c7d0d8f13e160be5660a1a27d5bb18861c

func Sha1SumHex

func Sha1SumHex(src, key, sum string) (string, error)

Sha1SumHex calculates the SHA-1 digest to sum and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha1SumHex("goyy", "key", "goyy:")
	fmt.Println(dst)

}
Output:

676f79793a221f50c7d0d8f13e160be5660a1a27d5bb18861c

func Sha256

func Sha256(src, key []byte) ([]byte, error)

Sha256 calculates the SHA-256 digest and returns the value as a byte[].

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha256([]byte("goyy"), []byte("key"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

840f83ba7e39cc809ea5ff9829da11070b21aaf4f306a356d0eb782a7c09f54a

func Sha256Hex

func Sha256Hex(src, key string) (string, error)

Sha256Hex calculates the SHA-256 digest and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha256Hex("goyy", "key")
	fmt.Println(dst)

}
Output:

840f83ba7e39cc809ea5ff9829da11070b21aaf4f306a356d0eb782a7c09f54a

func Sha256Sum

func Sha256Sum(src, key, sum []byte) ([]byte, error)

Sha256Sum calculates the SHA-256 digest to sum and returns the resulting slice.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha256Sum([]byte("goyy"), []byte("key"), []byte("goyy:"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

676f79793a840f83ba7e39cc809ea5ff9829da11070b21aaf4f306a356d0eb782a7c09f54a

func Sha256SumHex

func Sha256SumHex(src, key, sum string) (string, error)

Sha256SumHex calculates the SHA-256 digest to sum and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha256SumHex("goyy", "key", "goyy:")
	fmt.Println(dst)

}
Output:

676f79793a840f83ba7e39cc809ea5ff9829da11070b21aaf4f306a356d0eb782a7c09f54a

func Sha512

func Sha512(src, key []byte) ([]byte, error)

Sha512 calculates the SHA-512 digest and returns the value as a byte[].

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha512([]byte("goyy"), []byte("key"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

ecaefb579a65c35352558f88a6b691199884784bfd35deb997ec1e40d20cc99d49d586a59e7b4c6a6e8c250e8dd16262547e991bd9e32f5da722f071230308c3

func Sha512Hex

func Sha512Hex(src, key string) (string, error)

Sha512Hex calculates the SHA-512 digest and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha512Hex("goyy", "key")
	fmt.Println(dst)

}
Output:

ecaefb579a65c35352558f88a6b691199884784bfd35deb997ec1e40d20cc99d49d586a59e7b4c6a6e8c250e8dd16262547e991bd9e32f5da722f071230308c3

func Sha512Sum

func Sha512Sum(src, key, sum []byte) ([]byte, error)

Sha512Sum calculates the SHA-512 digest to sum and returns the resulting slice.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha512Sum([]byte("goyy"), []byte("key"), []byte("goyy:"))
	fmt.Println(fmt.Sprintf("%x", dst))

}
Output:

676f79793aecaefb579a65c35352558f88a6b691199884784bfd35deb997ec1e40d20cc99d49d586a59e7b4c6a6e8c250e8dd16262547e991bd9e32f5da722f071230308c3

func Sha512SumHex

func Sha512SumHex(src, key, sum string) (string, error)

Sha512SumHex calculates the SHA-512 digest to sum and returns the resulting hex string.

Example
package main

import (
	"fmt"

	"gopkg.in/goyy/goyy.v0/util/crypto/hmac"
)

func main() {
	dst, _ := hmac.Sha512SumHex("goyy", "key", "goyy:")
	fmt.Println(dst)

}
Output:

676f79793aecaefb579a65c35352558f88a6b691199884784bfd35deb997ec1e40d20cc99d49d586a59e7b4c6a6e8c250e8dd16262547e991bd9e32f5da722f071230308c3

Types

This section is empty.

Jump to

Keyboard shortcuts

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