crypto

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: 0 Imported by: 0

README

util-crypto GoDoc

General encoding/decoding algorithms library for Go

Installation

go get gopkg.in/goyy/goyy.v0/util/crypto

Usage

MD5

dst, _ := md5.DigestHex("goyy")
fmt.Println(dst)
// Output:db9e2a3e99dbace8332b3042a6beb793

SHA1

dst, _ := sha1.DigestHex("goyy")
fmt.Println(dst)
// Output:9a5de4d2e62e2c0f3018eeff35e09ab3d41781fb

AES

dst, _ := aes.EncryptHex("goyy", "key")
fmt.Println(dst)
// Output:efe9f867

dst, _ := aes.DecryptHex("efe9f867", "key")
fmt.Println(dst)
// Output:goyy

RSA

var privateKey = `
-----BEGIN RSA PRIVATE KEY-----
MIIBOwIBAAJBAM7ews9ZrWeDybHsThj03sUa3AqpQ+aR0wcDfzNf1QgorJ8u0u+5
WebCh8Fl2OZkuJvkqNDO+QeUQGvenLHHCbsCAwEAAQJBAJ2LywNNAaG/HUFSfNvG
yU2FOiUoaZzUW8mQoTQH/N67dHm6kQqTDTp0ppRkB8DyXjdpgyqquhGfFujfnrmj
51ECIQDwU3oSC+AmQy/YmKjfu6eL8SZaKsAf6CWcOjhqkMDHMwIhANxcsttcWgvl
VtztF/FcS8YR8rAkaiczpTEsY53cIxNZAiEAxgXyssYIR17bIN0BYYEtmFj3IhrR
vji6LNWoQN7PihMCIFfnRpXIxkbeioMAtT9bwQJXIIdxT0MqD+iIu4g6S2epAiA3
aI9Exlhsv47JCGs3ZCN5JpD7XVAdo2t629s7pwPfnA==
-----END RSA PRIVATE KEY-----
`

var publicKey = `
-----BEGIN RSA PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAM7ews9ZrWeDybHsThj03sUa3AqpQ+aR
0wcDfzNf1QgorJ8u0u+5WebCh8Fl2OZkuJvkqNDO+QeUQGvenLHHCbsCAwEAAQ==
-----END RSA PUBLIC KEY-----
`

in := "goyy"
out, _ := rsa.EncryptHex(in, publicKey)
dst, _ := rsa.DecryptHex(out, privateKey)
fmt.Println(in == dst)
// Output:true

Documentation

Overview

A simplified wrapper around crypto package.

Directories

Path Synopsis
Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
Package aes implements AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.
Package des implements the Data Encryption Standard (DES) and the Triple Data Encryption Algorithm (TDEA) as defined in U.S. Federal Information Processing Standards Publication 46-3.
Package des implements the Data Encryption Standard (DES) and the Triple Data Encryption Algorithm (TDEA) as defined in U.S. Federal Information Processing Standards Publication 46-3.
Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.
Package hmac implements the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198.
Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
Package md5 implements the MD5 hash algorithm as defined in RFC 1321.
Package rc4 implements RC4 encryption, as defined in Bruce Schneier's Applied Cryptography.
Package rc4 implements RC4 encryption, as defined in Bruce Schneier's Applied Cryptography.
Package rsa implements RSA encryption as specified in PKCS#1.
Package rsa implements RSA encryption as specified in PKCS#1.
Package sha1 implements the SHA1 hash algorithm as defined in RFC 3174.
Package sha1 implements the SHA1 hash algorithm as defined in RFC 3174.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-2.
Package sha256 implements the SHA224 and SHA256 hash algorithms as defined in FIPS 180-2.
Package sha512 implements the SHA384 and SHA512 hash algorithms as defined in FIPS 180-2.
Package sha512 implements the SHA384 and SHA512 hash algorithms as defined in FIPS 180-2.

Jump to

Keyboard shortcuts

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