crypto

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

crypto utility pkg.

Index

Constants

View Source
const (
	// PKI X.509, public key start
	PubPemBegin = "-----BEGIN PUBLIC KEY-----"

	// PKCS8, private key start
	PrivPemBegin = "-----BEGIN PRIVATE KEY-----"

	// PKCS8, private key end
	PrivPemEnd = "-----END PRIVATE KEY-----"
)

Variables

View Source
var (
	ErrDecodePemFailed = errors.New("failed to decode public key pem")
	ErrInvalidKey      = errors.New("invalid key")
)

Functions

func AesEcbDecrypt added in v0.1.1

func AesEcbDecrypt(secret []byte, s string) (string, error)

AES/ECB/PKCSPadding decode hex string and decrypt.

func AesEcbEncrypt added in v0.1.1

func AesEcbEncrypt(secret []byte, plain string) (string, error)

AES/ECB/PKCSPadding encrypt and encoded as hex string.

func LoadPrivKey

func LoadPrivKey(content string) (*rsa.PrivateKey, error)

Load RSA PrivateKey from content.

Content should be PKCS8 compatible format with or without '-----BEGIN PRIVATE KEY-----' prefix and suffix.

func LoadPubKey

func LoadPubKey(content string) (*rsa.PublicKey, error)

Load RSA PublicKey from content.

Content should be X.509 compatible format with or without '-----BEGIN PUBLIC KEY-----' prefix and suffix.

func MD5Hex added in v0.3.11

func MD5Hex(b []byte) string

func MD5HexStr added in v0.4.4

func MD5HexStr(b string) string

func NewECBDecrypter added in v0.1.1

func NewECBDecrypter(b cipher.Block) cipher.BlockMode

ECB block mode for decryption.

func NewECBEncrypter added in v0.1.1

func NewECBEncrypter(b cipher.Block) cipher.BlockMode

ECB block mode for encryption.

func PKCSPadding added in v0.1.1

func PKCSPadding(ciphertext []byte, blockSize int) []byte

PKCS5/7 Padding

func PKCSTrimming added in v0.1.1

func PKCSTrimming(encrypt []byte) []byte

PKCS5/7 Trimming

func SHA1Hex added in v0.4.4

func SHA1Hex(b []byte) string

func SHA1HexStr added in v0.4.4

func SHA1HexStr(b string) string

func SHA256Hex added in v0.4.10

func SHA256Hex(b []byte) string

func SHA256HexStr added in v0.4.10

func SHA256HexStr(b string) string

func SHA512Hex added in v0.4.10

func SHA512Hex(b []byte) string

func SHA512HexStr added in v0.4.10

func SHA512HexStr(b string) string

Types

type ECBDecrypter added in v0.1.1

type ECBDecrypter ecb

func (*ECBDecrypter) BlockSize added in v0.1.1

func (ec *ECBDecrypter) BlockSize() int

func (*ECBDecrypter) CryptBlocks added in v0.1.1

func (ec *ECBDecrypter) CryptBlocks(dst, src []byte)

type ECBEncrypter added in v0.1.1

type ECBEncrypter ecb

func (*ECBEncrypter) BlockSize added in v0.1.1

func (ec *ECBEncrypter) BlockSize() int

func (*ECBEncrypter) CryptBlocks added in v0.1.1

func (ec *ECBEncrypter) CryptBlocks(dst, src []byte)

Jump to

Keyboard shortcuts

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