crypto

package
v0.0.54 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(c, key []byte) ([]byte, error)

AESCBCDecrypt decrypts cipher text with AES algorithm in CBC mode. Note that key length must be 16, 24 or 32 bytes to select AES-128, AES-192, or AES-256.

func AESCBCEncrypt

func AESCBCEncrypt(p, key []byte) ([]byte, error)

AESCBCEncrypt encrypts data with AES algorithm in CBC mode. Note that key length must be 16, 24 or 32 bytes to select AES-128, AES-192, or AES-256.

func Base64AESCBCDecrypt

func Base64AESCBCDecrypt(c string, key []byte) ([]byte, error)

Base64AESCBCDecrypt decrypts cipher text encoded by base64 with AES algorithm in CBC mode.

func Base64AESCBCEncrypt

func Base64AESCBCEncrypt(p, key []byte) (string, error)

Base64AESCBCEncrypt encrypts data with AES algorithm in CBC mode and then encode using base64.

func Base64DESCBCDecrypt

func Base64DESCBCDecrypt(c string, key []byte) ([]byte, error)

Base64DESCBCDecrypt decrypts cipher text encoded by base64 with DES algorithm in CBC mode.

func Base64DESCBCEncrypt

func Base64DESCBCEncrypt(p, key []byte) (string, error)

Base64DESCBCEncrypt encrypts data with DES algorithm in CBC mode and encoded by base64.

func Base64TriDESCBCDecrypt

func Base64TriDESCBCDecrypt(c string, key []byte) ([]byte, error)

Base64TriDESCBCDecrypt decrypts cipher text encoded by base64 with 3DES algorithm in CBC mode.

func Base64TriDESCBCEncrypt

func Base64TriDESCBCEncrypt(p, key []byte) (string, error)

Base64TriDESCBCEncrypt encrypts data with 3DES algorithm in CBC mode and encoded by base64.

func DESCBCDecrypt

func DESCBCDecrypt(c, key []byte) ([]byte, error)

DESCBCDecrypt decrypts cipher text with DES algorithm in CBC mode. Note that key length must be 8 bytes.

func DESCBCEncrypt

func DESCBCEncrypt(p, key []byte) ([]byte, error)

DESCBCEncrypt encrypts data with DES algorithm in CBC mode. Note that key length must be 8 bytes.

func GenRsaKey

func GenRsaKey(bits int) (prvkey, pubkey []byte, err error)

GenRsaKey generates an PKCS#1 RSA keypair of the given bit size in PEM format.

func HMAC

func HMAC(str, key string, hashName string, capital bool) string

HMAC generates authentication code based on specified hash algorithm. e.g. HMAC("", "", "MD5", false) returns 74e6f7298a9c2d168935f58c001bad88.

func HMACMD5

func HMACMD5(str, key string) string

HMACMD5 generates 32 uppercase hexadecimal characters authentication code based on MD5.

func HMACMd5

func HMACMd5(str, key string) string

HMACMd5 generates 32 lowercase hexadecimal characters authentication code based on MD5.

func HMACSHA1

func HMACSHA1(str, key string) string

HMACSHA1 generates 40 uppercase hexadecimal characters authentication code based on SHA1.

func HMACSHA224

func HMACSHA224(str, key string) string

HMACSHA224 generates 56 uppercase hexadecimal characters authentication code based on SHA224.

func HMACSHA256

func HMACSHA256(str, key string) string

HMACSHA256 generates 64 uppercase hexadecimal characters authentication code based on SHA256.

func HMACSHA384

func HMACSHA384(str, key string) string

HMACSHA384 generates 96 uppercase hexadecimal characters authentication code based on SHA384.

func HMACSHA512

func HMACSHA512(str, key string) string

HMACSHA512 generates 128 uppercase hexadecimal characters authentication code based on SHA512.

func HMACSha1

func HMACSha1(str, key string) string

HMACSha1 generates 40 lowercase hexadecimal characters authentication code based on SHA1.

func HMACSha224

func HMACSha224(str, key string) string

HMACSha224 generates 56 lowercase hexadecimal characters authentication code based on SHA224.

func HMACSha256

func HMACSha256(str, key string) string

HMACSha256 generates 64 lowercase hexadecimal characters authentication code based on SHA256.

func HMACSha384

func HMACSha384(str, key string) string

HMACSha384 generates 96 lowercase hexadecimal characters authentication code based on SHA384.

func HMACSha512

func HMACSha512(str, key string) string

HMACSha512 generates 128 lowercase hexadecimal characters authentication code based on SHA512.

func Hash

func Hash(s string, name string, capital bool) string

Hash generates a checksum of the specified hash algorithm. E.g. Hash("", "MD5", false) returns d41d8cd98f00b204e9800998ecf8427e.

func MD5

func MD5(s string) string

MD5 generates 32 uppercase hexadecimal characters of MD5 value.

func Md5

func Md5(s string) string

Md5 generates 32 lowercase hexadecimal characters of MD5 value.

func PKCS7Padding

func PKCS7Padding(p []byte, blockSize int) []byte

PKCS7Padding fills plaintext as an integral multiple of the block length. In cryptography, PKCS stands for "Public Key Cryptography Standards". These are a group of public key cryptography standards devised and published by RSA Security LLC, starting in the early 1990s. PKCS#7 is Cryptographic Message Syntax Standard used to sign and/or encrypt messages under a PKI. More information about PKCS#7 please refer to the RFC 2315. The PKCS#7 padding method works by adding bytes that all have the same value as the number of bytes added to the plaintext. For example, if the last block of plaintext is 3 bytes long and the block size is 8 bytes, then 5 bytes of padding are added to make the total length of the plaintext 8 bytes. The value of the 5 bytes will be the hex value 0x05, since 5 bytes were added as padding.

func PKCS7UnPadding

func PKCS7UnPadding(p []byte) ([]byte, error)

PKCS7UnPadding removes padding data from the tail of plaintext.

func RsaDecrypt

func RsaDecrypt(prvkey, cipher []byte) ([]byte, error)

RsaDecrypt decrypts data using rsa private key.

func RsaEncrypt

func RsaEncrypt(pubkey, data []byte) ([]byte, error)

RsaEncrypt encrypts data using rsa public key.

func RsaSign

func RsaSign(prvkey []byte, hash crypto.Hash, data []byte) ([]byte, error)

RsaSign signs using private key in PEM format.

func RsaVerifySign

func RsaVerifySign(pubkey []byte, hash crypto.Hash, data, sig []byte) error

RsaVerifySign verifies signature using public key in PEM format. A valid signature is indicated by returning a nil error.

func SHA1

func SHA1(s string) string

SHA1 generates 40 uppercase hexadecimal characters of SHA1 value.

func SHA224

func SHA224(s string) string

SHA224 generates 56 uppercase hexadecimal characters of SHA224 value.

func SHA256

func SHA256(s string) string

SHA256 generates 64 uppercase hexadecimal characters of SHA256 value.

func SHA384

func SHA384(s string) string

SHA384 generates 96 uppercase hexadecimal characters of SHA384 value.

func SHA512

func SHA512(s string) string

SHA512 generates 128 uppercase hexadecimal characters of SHA512 value.

func Sha1

func Sha1(s string) string

Sha1 generates 40 lowercase hexadecimal characters of SHA1 value.

func Sha224

func Sha224(s string) string

Sha224 generates 56 lowercase hexadecimal characters of SHA224 value.

func Sha256

func Sha256(s string) string

Sha256 generates 64 lowercase hexadecimal characters of SHA256 value.

func Sha384

func Sha384(s string) string

Sha384 generates 96 lowercase hexadecimal characters of SHA384 value.

func Sha512

func Sha512(s string) string

Sha512 generates 128 lowercase hexadecimal characters of SHA512 value.

func TriDESCBCDecrypt

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

TriDESCBCDecrypt decrypts cipher text with 3DES algorithm in CBC mode. Note that key length must be 24 bytes

func TriDESCBCEncrypt

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

TriDESCBCEncrypt encrypts data with 3DES algorithm in CBC mode. Note that key length must be 24 bytes

Types

This section is empty.

Jump to

Keyboard shortcuts

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