crypto

package
v0.0.0-...-2e81f5e Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ZerosPaddingMode = paddingMode(`Zeros`)
	PKCS5PaddingMode = paddingMode(`PKCS5`)
)

padding modes

Variables

View Source
var (
	ErrParam  = errors.New("invalid parameters")
	ErrVerify = errors.New("verify failed")
)

errors

Functions

func AESDecrypt

func AESDecrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

AESDecrypt : AES decrypt with CBC mode

func AESEncrypt

func AESEncrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

AESEncrypt : AES encrypt with CBC mode

func Base64DecodeSTD

func Base64DecodeSTD(src []byte) ([]byte, error)

Base64DecodeSTD : BASE64 decode

func Base64DecodeURL

func Base64DecodeURL(src []byte) ([]byte, error)

Base64DecodeURL : BASE64 decode for url

func Base64EncodeSTD

func Base64EncodeSTD(src []byte) []byte

Base64EncodeSTD : BASE64 encode

func Base64EncodeURL

func Base64EncodeURL(src []byte) []byte

Base64EncodeURL : BASE64 encode for url

func CalculateExchangeKey

func CalculateExchangeKey(comm *DHPulbic, private *DHKey, public *DHKey) (*big.Int, error)

CalculateExchangeKey : calculate exchange key

func DESDecrypt

func DESDecrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

DESDecrypt : DES decrypt with CBC mode

func DESEncrypt

func DESEncrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

DESEncrypt : DES encrypt with CBC mode

func GenerateRSAKey

func GenerateRSAKey(size int) ([]byte, []byte, error)

GenerateRSAKey : generate RSA key pair

func GetPadding

func GetPadding(mode paddingMode) (func([]byte, int) []byte, error)

GetPadding : get padding function

func GetUnpadding

func GetUnpadding(mode paddingMode) (func([]byte) []byte, error)

GetUnpadding : get unpadding function

func HMACHash

func HMACHash(hash stdcrypto.Hash, key []byte, src []byte) ([]byte, error)

HMACHash : generate message authentication code

func HMACHashFile

func HMACHashFile(hash stdcrypto.Hash, key []byte, file string) ([]byte, error)

HMACHashFile : generate message authentication code of file

func HMACVerify

func HMACVerify(hash stdcrypto.Hash, key []byte, src []byte, checksum []byte) error

HMACVerify : verify message authentication code

func HMACVerifyFile

func HMACVerifyFile(hash stdcrypto.Hash, key []byte, file string, checksum []byte) error

HMACVerifyFile : generate message authentication code of file

func MD5Hash

func MD5Hash(src []byte) ([]byte, error)

MD5Hash : calculate message digest with MD5

func MD5HashFile

func MD5HashFile(file string) ([]byte, error)

MD5HashFile : calculate message digest of file withc MD5

func RSADecrypt

func RSADecrypt(privatekey []byte, cipher []byte) ([]byte, error)

RSADecrypt : RSA decrypt with private key

func RSAEncrypt

func RSAEncrypt(publicKey []byte, originData []byte) ([]byte, error)

RSAEncrypt : RSA encrypt with public key

func SHA1Hash

func SHA1Hash(src []byte) ([]byte, error)

SHA1Hash : calculate message digest with SHA-1

func SHA1HashFile

func SHA1HashFile(file string) ([]byte, error)

SHA1HashFile : calculate message digest of file with SHA-1

func SHA256Hash

func SHA256Hash(src []byte) ([]byte, error)

SHA256Hash : calculate message digest with SHA-256

func SHA256HashFile

func SHA256HashFile(file string) ([]byte, error)

SHA256HashFile : calculate message digest of file with SHA-256

func SHA512Hash

func SHA512Hash(src []byte) ([]byte, error)

SHA512Hash : calculate message digest with SHA-512

func SHA512HashFile

func SHA512HashFile(file string) ([]byte, error)

SHA512HashFile : calculate message digest of file with SHA-512

func TripleDESDecrypt

func TripleDESDecrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

TripleDESDecrypt : 3DES decrypt with CBC mode

func TripleDESEncrypt

func TripleDESEncrypt(src []byte, key []byte, padding paddingMode) ([]byte, error)

TripleDESEncrypt : 3DES encrypt with CBC mode

Types

type DHKey

type DHKey struct {
	// contains filtered or unexported fields
}

DHKey : key pair

func GenerateKey

func GenerateKey(dhPulbic *DHPulbic, r io.Reader) (*DHKey, error)

GenerateKey : generate a key pair

func (*DHKey) Bytes

func (dhKey *DHKey) Bytes() []byte

Bytes : output bytes

func (*DHKey) SetPrivateKey

func (dhKey *DHKey) SetPrivateKey(private []byte)

SetPrivateKey : set x

func (*DHKey) SetPublicKey

func (dhKey *DHKey) SetPublicKey(public []byte)

SetPublicKey : set y

func (*DHKey) String

func (dhKey *DHKey) String() string

String : implement Stringer interface

type DHPulbic

type DHPulbic struct {
	// contains filtered or unexported fields
}

DHPulbic : public value

func GetDHPublic

func GetDHPublic(id int) (*DHPulbic, error)

GetDHPublic : get a DHPulbic by its ID as defined in either RFC 2409 or RFC 3526

func NewDHPublic

func NewDHPublic(base *big.Int, modulus *big.Int) (*DHPulbic, error)

NewDHPublic : create custom DHPublic WARNING: Do not use it if you do not know what you are doing

type HMAC

type HMAC struct {
	// contains filtered or unexported fields
}

HMAC : keyed-hash message authentication code

func NewHMAC

func NewHMAC(hash stdcrypto.Hash, key []byte) (*HMAC, error)

NewHMAC : create a new HMAC

Jump to

Keyboard shortcuts

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