crypto

package
v0.0.0-...-59dc93e Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AesCtrCrypt

func AesCtrCrypt(plainText []byte, key []byte) ([]byte, error)

AesCtrCrypt 加密、解密使用同一个函数

func AesDecryptCBC

func AesDecryptCBC(cryted []byte, key []byte) ([]byte, error)

func AesDecryptCFB

func AesDecryptCFB(encrypted []byte, key []byte) ([]byte, error)

func AesDecryptECB

func AesDecryptECB(encrypted []byte, key []byte) ([]byte, error)

func AesDecryptOFB

func AesDecryptOFB(data []byte, key []byte) ([]byte, error)

func AesEncryptCBC

func AesEncryptCBC(orig []byte, key []byte) ([]byte, error)

func AesEncryptCFB

func AesEncryptCFB(origData []byte, key []byte) ([]byte, error)

func AesEncryptECB

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

func AesEncryptOFB

func AesEncryptOFB(data []byte, key []byte) ([]byte, error)

func GenerateNonce

func GenerateNonce(size int) []byte

func GenerateStringNonce

func GenerateStringNonce(size int) string

func PKCS7Padding

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

PKCS7Padding 补码 AES加密数据块分组长度必须为128bit(byte[16]),密钥长度可以是128bit(byte[16])、192bit(byte[24])、256bit(byte[32])中的任意一个。

func PKCS7UnPadding

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

PKCS7UnPadding 去码

func PrivateBytesToPEM

func PrivateBytesToPEM(buf []byte) []byte

func PrivateKeyAsPEM

func PrivateKeyAsPEM(key *rsa.PrivateKey) []byte

PrivateKeyAsPEM takes a pointer to an RSA private key and returns its PEM encoding as a byte slice.

func PublicBytesToPEM

func PublicBytesToPEM(buf []byte) []byte

func PublicKeyAsPEM

func PublicKeyAsPEM(key *rsa.PublicKey) []byte

PublicKeyAsPEM takes a pointer to an RSA private key and returns its corresponding public key's PEM encoding as a byte slice.

func RandomBytes

func RandomBytes(size int) []byte

func RandomString

func RandomString(size int) string

func RsaDecrypt

func RsaDecrypt(ciphertext, privateKey []byte) ([]byte, error)

func RsaDecryptOAEP

func RsaDecryptOAEP(msg []byte, priv *rsa.PrivateKey) ([]byte, error)

RsaDecryptOAEP takes a message as a byte slice and an RSA private key, and returns the decrypted message as a byte slice.

func RsaEncrypt

func RsaEncrypt(origData, publicKey []byte) ([]byte, error)

func RsaEncryptOAEP

func RsaEncryptOAEP(msg []byte, pub *rsa.PublicKey) ([]byte, error)

RsaEncryptOAEP takes a message as a byte slice and an RSA public key, and returns the encrypted message as a byte slice.

func Sha1Digest

func Sha1Digest(data []byte) []byte

func Sha256Digest

func Sha256Digest(data []byte) []byte

Types

type ECDH

type ECDH interface {
	// GenerateKey 生成公私钥对
	GenerateKey() error
	// MarshalPublicKey 将公钥转换为字节
	MarshalPublicKey() []byte
	// MarshalPrivateKey 将私钥转换为字节
	MarshalPrivateKey() []byte
	// GenerateSharedSecret 生成共享密钥
	GenerateSharedSecret([]byte) ([]byte, []byte, error)
}

ECDH The main interface for ECDH key exchange.

func NewCurveKey

func NewCurveKey() ECDH

func NewRsaKey

func NewRsaKey() ECDH

type PasswordKdfAlgoModPow

type PasswordKdfAlgoModPow struct {
	Salt1 []byte
	Salt2 []byte
	G     int32
	P     []byte
}

type SRPUtil

type SRPUtil struct {
	*PasswordKdfAlgoModPow
	// contains filtered or unexported fields
}

func MakeSRPUtil

func MakeSRPUtil(algo *PasswordKdfAlgoModPow) *SRPUtil

func (*SRPUtil) CalcClientM

func (m *SRPUtil) CalcClientM(newSalt1, xBytes, srpB []byte) ([]byte, []byte)

func (*SRPUtil) CalcClientM2

func (m *SRPUtil) CalcClientM2(newSalt1, aBytes, ABytes, xBytes, srpB []byte) []byte

func (*SRPUtil) CalcM

func (m *SRPUtil) CalcM(newSalt1, vBytes, srpA, srpb, srpB []byte) []byte

func (*SRPUtil) CalcSRPB

func (m *SRPUtil) CalcSRPB(vBytes []byte) ([]byte, []byte)

func (*SRPUtil) CalcSRPB2

func (m *SRPUtil) CalcSRPB2(bNonce, vBytes []byte) []byte

func (*SRPUtil) CheckNewSalt1

func (m *SRPUtil) CheckNewSalt1(newSalt1 []byte) bool

func (*SRPUtil) GetV

func (m *SRPUtil) GetV(newSalt1, passwordBytes []byte) *big.Int

func (*SRPUtil) GetVBytes

func (m *SRPUtil) GetVBytes(newSalt1, passwordBytes []byte) []byte

func (*SRPUtil) GetX

func (m *SRPUtil) GetX(newSalt1, passwordBytes []byte) []byte

Jump to

Keyboard shortcuts

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