cryptox

package
v0.0.0-...-6ce63f4 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fnv32HashCode

func Fnv32HashCode(s string) uint32

func Fnv32aHashCode

func Fnv32aHashCode(s string) uint32

func Fnv64HashCode

func Fnv64HashCode(s string) uint64

func Fnv64aHashCode

func Fnv64aHashCode(s string) uint64

func GenRSAKey

func GenRSAKey(out io.Writer, bits int) error

func Md5

func Md5(s string) string

func Sha1

func Sha1(dst string) string

func Sha1WithSalt

func Sha1WithSalt(dst string, salt string) string

func Sha256

func Sha256(dst string) string

func Sha256WithSalt

func Sha256WithSalt(dst string, salt string) string

func Sha512

func Sha512(dst string) string

func Sha512WithSalt

func Sha512WithSalt(dst string, salt string) string

Types

type AES

type AES struct {
	AdditionalData []byte

	FixedNonce []byte
	// contains filtered or unexported fields
}

func NewAES

func NewAES(key []byte, opts ...OptFunc) (*AES, error)

func (*AES) Decrypt

func (x *AES) Decrypt(ciphertext any) (any, error)

func (*AES) DecryptWithBytes

func (x *AES) DecryptWithBytes(cipherBuf []byte) ([]byte, error)

func (*AES) DecryptWithString

func (x *AES) DecryptWithString(ciphertext string) (string, error)

func (*AES) Encrypt

func (x *AES) Encrypt(plaintext any) (any, error)

func (*AES) EncryptWithBytes

func (x *AES) EncryptWithBytes(plaintext []byte) ([]byte, error)

func (*AES) EncryptWithString

func (x *AES) EncryptWithString(plaintext string) (string, error)

func (*AES) NewNonce

func (x *AES) NewNonce() []byte

func (*AES) NewNonceStr

func (x *AES) NewNonceStr() string

type HexEncoder

type HexEncoder struct{}

func (HexEncoder) DecodeString

func (h HexEncoder) DecodeString(s string) ([]byte, error)

func (HexEncoder) EncodeToString

func (h HexEncoder) EncodeToString(b []byte) string

type OptFunc

type OptFunc func(c *AES)

func AESOptWithDataByte

func AESOptWithDataByte(data []byte) OptFunc

func AESOptWithEncoder

func AESOptWithEncoder(i encoder) OptFunc

func AESOptWithFixedNonce

func AESOptWithFixedNonce(nonce []byte) OptFunc

AESOptWithFixedNonce sets the fixed nonce for the AES encryption. This setting enables the same string to be encrypted with the same result. This is needed in some business scenarios. However, it should be used with caution as it can lead to security vulnerabilities. If not sets this option will generate a new nonce for each encryption.

func AESOptWithNonceSize

func AESOptWithNonceSize(size int) OptFunc

AESOptWithNonceSize sets the nonce size for the AES encryption. The default nonce size is 12 bytes, which is the recommended size. If you need to use a different nonce size, you can set it using this option. NOTE: If you set a fixed nonce, this setting will be invalid.

type RSA

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

func NewRSA

func NewRSA(private []byte) (*RSA, error)

func (*RSA) Decrypt

func (r *RSA) Decrypt(ciphertext any) (any, error)

func (*RSA) DecryptPKCS1v15

func (r *RSA) DecryptPKCS1v15(ciphertext []byte) ([]byte, error)

DecryptPKCS1v15 decrypts AdditionalData with private key

func (*RSA) DecryptWithBytes

func (r *RSA) DecryptWithBytes(ciphertext []byte) ([]byte, error)

DecryptWithBytes decrypts AdditionalData with private key

func (*RSA) DecryptWithString

func (r *RSA) DecryptWithString(ciphertext string) (string, error)

func (*RSA) Encrypt

func (r *RSA) Encrypt(plaintext any) (any, error)

func (*RSA) EncryptPKCS1v15

func (r *RSA) EncryptPKCS1v15(msg []byte) ([]byte, error)

EncryptPKCS1v15 encrypts AdditionalData with public key

func (*RSA) EncryptWithBytes

func (r *RSA) EncryptWithBytes(msg []byte) ([]byte, error)

EncryptWithBytes encrypts AdditionalData with public key

func (*RSA) EncryptWithString

func (r *RSA) EncryptWithString(plaintext string) (string, error)

func (*RSA) SetPrivateKey

func (r *RSA) SetPrivateKey(private []byte) error

SetPrivateKey bytes to private key

func (*RSA) SetPrivateKeyByBase64

func (r *RSA) SetPrivateKeyByBase64(privateStr string) error

SetPrivateKeyByBase64 Get bytes AdditionalData by decoding base64 string

func (*RSA) SetPublicKey

func (r *RSA) SetPublicKey(public []byte) error

SetPublicKey bytes to public key

func (*RSA) SetPublicKeyByBase64

func (r *RSA) SetPublicKeyByBase64(publicStr string) error

SetPublicKeyByBase64 Get bytes AdditionalData by decoding base64 string

Jump to

Keyboard shortcuts

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