ncrypto

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 21 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPadding = errors.New("invalid padding")
)

Functions

func AESCBCDecrypt

func AESCBCDecrypt(ciphertext, key, iv []byte, padding Padding) ([]byte, error)

func AESCBCDecryptWithSalt

func AESCBCDecryptWithSalt(data, key []byte, iter int, magic string, padding Padding, h func() hash.Hash) ([]byte, error)

func AESCBCEncrypt

func AESCBCEncrypt(plaintext, key, iv []byte, padding Padding) ([]byte, error)

AESCBCEncrypt 由key的长度决定是128, 192 还是 256

func AESCBCEncryptWithSalt

func AESCBCEncryptWithSalt(plaintext, key []byte, iter int, magic string, padding Padding, h func() hash.Hash) ([]byte, error)

func AESCFBDecrypt

func AESCFBDecrypt(ciphertext, key, iv []byte, padding Padding) ([]byte, error)

func AESCFBEncrypt

func AESCFBEncrypt(plaintext, key, iv []byte, padding Padding) ([]byte, error)

func AESDecryptWithSalt

func AESDecryptWithSalt(ciphertext, key []byte, iterCount int, magic string, h func() hash.Hash, padding Padding, f func(ciphertext, key, iv []byte, padding Padding) ([]byte, error)) ([]byte, error)

func AESECBDecrypt

func AESECBDecrypt(ciphertext, key []byte, padding Padding) ([]byte, error)

func AESECBEncrypt

func AESECBEncrypt(plaintext, key []byte, padding Padding) ([]byte, error)

func AESEncryptWithSalt

func AESEncryptWithSalt(plaintext, key []byte, iter int, magic string, h func() hash.Hash, padding Padding, f func(plaintext, key, iv []byte, padding Padding) ([]byte, error)) ([]byte, error)

func AESGCMDecrypt

func AESGCMDecrypt(ciphertext, key, additional []byte) ([]byte, error)

func AESGCMDecryptWithNonce

func AESGCMDecryptWithNonce(ciphertext, key, nonce, additional []byte) ([]byte, error)

func AESGCMEncrypt

func AESGCMEncrypt(plaintext, key, additional []byte) ([]byte, error)

func AESGCMEncryptWithNonce

func AESGCMEncryptWithNonce(plaintext, key, nonce, additional []byte) ([]byte, error)

func DecodeCertificate

func DecodeCertificate(data []byte) (*x509.Certificate, error)

func GenerateRSAKeyPair

func GenerateRSAKeyPair(bits int) (*rsa.PrivateKey, *rsa.PublicKey, error)

func HmacMD5

func HmacMD5(data, key []byte) []byte

func HmacSHA1

func HmacSHA1(data, key []byte) []byte

func HmacSHA256

func HmacSHA256(data, key []byte) []byte

func HmacSHA512

func HmacSHA512(data, key []byte) []byte

func MD5

func MD5(value []byte) []byte

func RSADecrypt

func RSADecrypt(ciphertext []byte, key *rsa.PrivateKey) ([]byte, error)

RSADecrypt 使用私钥 key 对数据 ciphertext 进行解密

func RSAEncrypt

func RSAEncrypt(plaintext []byte, key *rsa.PublicKey) ([]byte, error)

RSAEncrypt 使用公钥 key 对数据 plaintext 进行加密

func RSASignPKCS1v15

func RSASignPKCS1v15(plaintext []byte, key *rsa.PrivateKey, hash crypto.Hash) ([]byte, error)

func RSAVerifyPKCS1v15

func RSAVerifyPKCS1v15(ciphertext, signature []byte, key *rsa.PublicKey, hash crypto.Hash) error

func RandBytes

func RandBytes(length int) (data []byte, err error)

func SHA1

func SHA1(value []byte) []byte

func SHA256

func SHA256(value []byte) []byte

func SHA512

func SHA512(value []byte) []byte

Types

type NoPadding

type NoPadding struct {
}

func (NoPadding) Pad

func (p NoPadding) Pad(src []byte, blockSize int) ([]byte, error)

func (NoPadding) UnPad

func (p NoPadding) UnPad(src []byte, blockSize int) ([]byte, error)

type PKCS1PrivateKey

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

func (PKCS1PrivateKey) RSAPrivateKey

func (p PKCS1PrivateKey) RSAPrivateKey() (*rsa.PrivateKey, error)

type PKCS1PublicKey

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

func (PKCS1PublicKey) RSAPublicKey

func (p PKCS1PublicKey) RSAPublicKey() (*rsa.PublicKey, error)

type PKCS5Padding

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

func (PKCS5Padding) Pad

func (p PKCS5Padding) Pad(src []byte, blockSize int) ([]byte, error)

func (PKCS5Padding) UnPad

func (p PKCS5Padding) UnPad(src []byte, blockSize int) ([]byte, error)

type PKCS7Padding

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

func (PKCS7Padding) Pad

func (p PKCS7Padding) Pad(src []byte, blockSize int) ([]byte, error)

func (PKCS7Padding) UnPad

func (p PKCS7Padding) UnPad(src []byte, blockSize int) ([]byte, error)

type PKCS8PrivateKey

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

func (PKCS8PrivateKey) ECDSAPrivateKey

func (p PKCS8PrivateKey) ECDSAPrivateKey() (*ecdsa.PrivateKey, error)

func (PKCS8PrivateKey) ED25519PrivateKey

func (p PKCS8PrivateKey) ED25519PrivateKey() (*ed25519.PrivateKey, error)

func (PKCS8PrivateKey) PrivateKey

func (p PKCS8PrivateKey) PrivateKey() (any, error)

func (PKCS8PrivateKey) RSAPrivateKey

func (p PKCS8PrivateKey) RSAPrivateKey() (*rsa.PrivateKey, error)

type PKIXPublicKey

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

func (PKIXPublicKey) ECDSAPublicKey

func (p PKIXPublicKey) ECDSAPublicKey() (*ecdsa.PublicKey, error)

func (PKIXPublicKey) ED25519PublicKey

func (p PKIXPublicKey) ED25519PublicKey() (*ed25519.PublicKey, error)

func (PKIXPublicKey) PublicKey

func (p PKIXPublicKey) PublicKey() (any, error)

func (PKIXPublicKey) RSAPublicKey

func (p PKIXPublicKey) RSAPublicKey() (*rsa.PublicKey, error)

type Padding

type Padding interface {
	Pad(src []byte, blockSize int) ([]byte, error)

	UnPad(src []byte, blockSize int) ([]byte, error)
}

type PrivateKey

type PrivateKey interface {
	Public() crypto.PublicKey
	Equal(crypto.PrivateKey) bool
}

type PrivateKeyDecoder

type PrivateKeyDecoder []byte

func DecodePrivateKey

func DecodePrivateKey(data []byte) PrivateKeyDecoder

func (PrivateKeyDecoder) PKCS1

func (PrivateKeyDecoder) PKCS8

type PrivateKeyEncoder

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

func EncodePrivateKey

func EncodePrivateKey(key PrivateKey) PrivateKeyEncoder

func (PrivateKeyEncoder) PKCS1

func (p PrivateKeyEncoder) PKCS1() ([]byte, error)

func (PrivateKeyEncoder) PKCS8

func (p PrivateKeyEncoder) PKCS8() ([]byte, error)

type PublicKey

type PublicKey interface {
	Equal(crypto.PublicKey) bool
}

type PublicKeyDecoder

type PublicKeyDecoder []byte

func DecodePublicKey

func DecodePublicKey(data []byte) PublicKeyDecoder

func (PublicKeyDecoder) PKCS1

func (p PublicKeyDecoder) PKCS1() PKCS1PublicKey

func (PublicKeyDecoder) PKIX

type PublicKeyEncoder

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

func EncodePublicKey

func EncodePublicKey(key PublicKey) PublicKeyEncoder

func (PublicKeyEncoder) PKCS1

func (p PublicKeyEncoder) PKCS1() ([]byte, error)

func (PublicKeyEncoder) PKIX

func (p PublicKeyEncoder) PKIX() ([]byte, error)

type ZeroPadding

type ZeroPadding struct {
}

func (ZeroPadding) Pad

func (p ZeroPadding) Pad(src []byte, blockSize int) ([]byte, error)

func (ZeroPadding) UnPad

func (p ZeroPadding) UnPad(src []byte, blockSize int) ([]byte, error)

Directories

Path Synopsis
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pkcs12 implements some of PKCS#12.
Package pkcs12 implements some of PKCS#12.
internal/rc2
Package rc2 implements the RC2 cipher
Package rc2 implements the RC2 cipher

Jump to

Keyboard shortcuts

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