utils

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package debounce provides a debouncer func. The most typical use case would be the user typing a text into a form; the UI needs an update, but let's wait for a break.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(key []byte, text string) (string, error)

func AESCBCDecryptRaw

func AESCBCDecryptRaw(key []byte, decodedMsg []byte) (string, error)

func AESCBCDecryptSafety

func AESCBCDecryptSafety(key []byte, text string) (string, error)

func AESCBCEncrypt

func AESCBCEncrypt(key []byte, text string) (string, error)

func AESCBCEncryptRaw

func AESCBCEncryptRaw(key []byte, text string) ([]byte, error)

func AESCBCEncryptSafety

func AESCBCEncryptSafety(key []byte, text string) (string, error)

func AESCTRDecrypt

func AESCTRDecrypt(encryptData []byte, key []byte) ([]byte, error)

AESCTREncrypt AES-CTR Decrypt

func AESCTRDecryptWithBase64

func AESCTRDecryptWithBase64(encryptDataStr string, key []byte) (string, error)

AESCTRDecryptWithBase64 AES-CTR Decrypt

func AESCTREncrypt

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

AESCTREncrypt AES-CTR Encrypt

func AESCTREncryptWithBase64

func AESCTREncryptWithBase64(plainText []byte, key []byte) (string, error)

AESCTREncryptWithBase64 AES-CTR Encrypt

func AESMACDecryptBytes

func AESMACDecryptBytes(bytesIn []byte, passphrase string) (decrypted bool, plaintextBytes []byte, err error)

AESMACDecryptBytes takes in a byte slice from a file and a passphrase then returns if the encrypted byte slice was decrypted, if so the plaintext contents, and any errors

func AESMACDecryptBytesSafety

func AESMACDecryptBytesSafety(bytesIn []byte, passphrase string) (decrypted bool, plaintextBytes []byte, err error)

AESMACDecryptBytesSafety takes in a byte slice from a file and a passphrase then returns if the encrypted byte slice was decrypted, if so the plaintext contents, and any errors

func AESMACEncryptBytes

func AESMACEncryptBytes(bytesIn []byte, passphrase string) []byte

AESMACEncryptBytes is a function that takes a plain byte slice and a passphrase and returns an encrypted byte slice

func AESMACEncryptBytesSafety

func AESMACEncryptBytesSafety(bytesIn []byte, passphrase string) string

AESMACEncryptBytesSafety is a function that takes a plain byte slice and a passphrase and returns an encrypted byte slice

func Base64DecodeBytesToBytes

func Base64DecodeBytesToBytes(input []byte) ([]byte, error)

Base64DecodeBytesToStr converts a Base64 byte slice to a Base64 Decoded Byte slice

func Base64DecodeStrToBytes

func Base64DecodeStrToBytes(input string) ([]byte, error)

Base64DecodeStrToBytes converts a Base64 string to a Base64 Decoded Byte slice

func Base64DecodeStrToStr

func Base64DecodeStrToStr(input string) (string, error)

Base64DecodeStrToStr converts a Base64 string to a Base64 Decoded String

func Base64EncodeBytesToStr

func Base64EncodeBytesToStr(input []byte) string

Base64EncodeBytesToStr converts a byte slice to a Base64 Encoded String

func Base64EncodeStrToStr

func Base64EncodeStrToStr(input string) string

Base64EncodeStrToStr converts a string to a Base64 Encoded String

func Base64SafetyDecode

func Base64SafetyDecode(data string) ([]byte, error)

Base64SafetyDecode

func Base64SafetyEncode

func Base64SafetyEncode(text string) string

Base64SafetyEncode

func Check

func Check(e error)

check does error checking

func CheckURL

func CheckURL(urlStr string) error

func CreateDirectoryIfNotExists added in v0.1.6

func CreateDirectoryIfNotExists(filePath, filename string) (string, error)

CreateDirectoryIfNotExists This function, CreateDirectoryIfNotExists(filePath, filename string) (string, error), takes two string arguments, filePath and filename. The function first checks if the given filePath contains a filename. If it does not, it means that the provided filePath is a directory, and the function appends the filename to the path. Next, the function extracts the directory in which the file is located and checks if the directory exists. If the directory does not exist, it creates a new directory. Finally, the function returns the updated file path.

func CurrentDir

func CurrentDir() string

CurrentDir get the directory of the current executable file

func CurrentFile

func CurrentFile() string

CurrentFile get the current file path

func Debounce

func Debounce(after time.Duration) func(f func())

New returns a debounced function that takes another functions as its argument. This function will be called when the debounced function stops being called for the given duration. The debounced function can be invoked with different functions, if needed, the last one will win.

func DeleteRSAKeyPair

func DeleteRSAKeyPair(path string) error

DeleteRSAKeyPair delete key pair files

func FileExists

func FileExists(fileName string) (bool, error)

FileExists checks if a file exists and returns a boolean or an error

func FileSHA256

func FileSHA256(filePath string) (string, error)

FileSHA256 The sha256 hash of the file

func GenerateRSAKeypair

func GenerateRSAKeypair(keySize int) (*rsa.PrivateKey, *rsa.PublicKey, error)

GenerateRSAKeypair returns a private RSA key pair object

func GenerateRSAKeypairPEM

func GenerateRSAKeypairPEM(keySize int, rsaPrivateKeyPassword string) (privKeyPEM *bytes.Buffer, encryptedPrivKeyPEMBase64 string, publicKeyPEM *bytes.Buffer, err error)

func GetMachineID

func GetMachineID() string

func GetMachineIDUseSHA256

func GetMachineIDUseSHA256() string

func GetSha1Str

func GetSha1Str(str string) string

func GetSha256Str

func GetSha256Str(str string) string

func MakeDirIfNotExist

func MakeDirIfNotExist(path string)

MakeDirIfNotExist create if the folder does not exist

func PassphraseToHash

func PassphraseToHash(pass string) (string, []byte)

PassphraseToHash returns a hexadecimal string of an SHA1 checksumed passphrase

func PemEncodeRSAPrivateKey

func PemEncodeRSAPrivateKey(privKey *rsa.PrivateKey, rsaPrivateKeyPassword string) (privKeyPEM *bytes.Buffer, encryptedPrivKeyPEMBase64 string)

PemEncodeRSAPrivateKey creates a PEM from an RSA Private key, and optionally returns an encrypted version

func PemEncodeRSAPublicKey

func PemEncodeRSAPublicKey(caPubKey *rsa.PublicKey) (*bytes.Buffer, error)

PemEncodeRSAPublicKey takes a DER formatted RSA Public Key object and converts it to PEM format

func PemToEncryptedBytes

func PemToEncryptedBytes(pem *bytes.Buffer, passphrase string) (b *bytes.Buffer)

PemToEncryptedBytes takes a PEM byte buffer and encrypts it

func ReadFileToBytes

func ReadFileToBytes(path string) ([]byte, error)

ReadFileToBytes will return the contents of a file as a byte slice

func RsaDecrypt

func RsaDecrypt(cipherText, keyBytes []byte) []byte

私钥解密

func RsaDecryptWithSha1Base64

func RsaDecryptWithSha1Base64(encryptedData, privateKey string) (string, error)

RsaDecryptWithSha1Base64 解密:对采用sha1算法加密后转base64格式的数据进行解密(私钥PKCS1格式)

func RsaEncrypt

func RsaEncrypt(data, keyBytes []byte) []byte

公钥加密

func RsaEncryptWithSha1Base64

func RsaEncryptWithSha1Base64(originalData, publicKey string) (string, error)

RsaEncryptWithSha1Base64 加密:采用sha1算法加密后转base64格式

func RsaSignWithSha1Hex

func RsaSignWithSha1Hex(data string, prvKey string) (string, error)

RsaSignWithSha1Hex 签名:采用sha1算法进行签名并输出为hex格式(私钥PKCS8格式)

func RsaSignWithSha1HexPkcs1

func RsaSignWithSha1HexPkcs1(data string, pkcs1keyStr string) ([]byte, error)

RsaSignWithSha1HexPkcs1 签名:采用sha1算法进行签名并输出为hex格式(私钥PKCS1格式)

func RsaSignWithSha256

func RsaSignWithSha256(data []byte, keyBytes []byte) []byte

RsaSignWithSha256

func RsaVerySignWithSha1Base64

func RsaVerySignWithSha1Base64(originalData, signData, pubKey string) error

RsaVerySignWithSha1Base64 验签:对采用sha1算法进行签名后转base64格式的数据进行验签

func RsaVerySignWithSha256

func RsaVerySignWithSha256(data, signData, keyBytes []byte) bool

RsaVerySignWithSha256

func WriteByteFile

func WriteByteFile(path string, content []byte, mode int, overwrite bool) (bool, error)

WriteByteFile creates a file from a byte slice with an optional file mode, only if it's new, and populates it - can force overwrite optionally

func WriteKeyFile

func WriteKeyFile(pem *bytes.Buffer, path string, permission int) (bool, error)

WriteKeyFile writes a public or private key file depending on the permissions, 644 for public, 400 for private

func WriteRSAKeyPair

func WriteRSAKeyPair(privKey *bytes.Buffer, pubKey *bytes.Buffer, path string) (bool, bool, error)

WriteRSAKeyPair creates key pair files

Types

This section is empty.

Jump to

Keyboard shortcuts

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