EncryptionFile

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

EncryptionFile

中文文档

for specific usage, please read: EncryptionFile_test.go

implementation

the password is related to the corresponding algorithm

I have this format here: password = [key + 0 + iv/nonce]

rsa ciphertext length rsa encrypted password data algorithm encrypted content hash value
len(rsa(password)) rsa(password) algorithm(content) hash.Sum(len(rsa(password)) + rsa(password) + algorithm(content))

cipher.AEAD

password composition: password = [key + 0 + nonce]

the nonce needs to be taken out correctly, and it must be ensured that there is no 0 in the key

cipher.Stream

password composition: password = [key + 0 + iv]

cipher.BlockMode

password composition: password = [key + 0 + iv]

example

support encryption schemes in golang standard library: cipher.AEAD,cipher.Stream,cipher.BlockMode

at the same time, several encryption schemes of aes are built in: CFB,CTR,OFB,CBC,GCM

// an encryption scheme can be specified with the built-in method
// GenEncCipher(cipher.NewCFBEncrypter)
// GenEncCipher(cipher.NewCTR)
// GenEncCipher(cipher.NewOFB)
// GenEncCipher(cipher.NewCBCEncrypter)
// GenEncCipher(cipher.NewGCM)
EncData(Reader, Writer, pubKey, md5.New(), GenEncCipher(cipher.NewCFBEncrypter))

// an decryption scheme can be specified with the built-in method
// GenDecCipher(cipher.NewCFBDecrypter)
// GenDecCipher(cipher.NewCTR)
// GenDecCipher(cipher.NewOFB)
// GenDecCipher(cipher.NewCBCDecrypter)
// GenDecCipher(cipher.NewGCM)
DecData(Reader, Writer, priKey, md5.New(), GenDecCipher(cipher.NewCFBDecrypter))

you can also refer to GenEncCipher to write the method of generating encryption

you can also refer to GenDecCipher to write the method of generating decryption

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecData

func DecData(r io.Reader, w io.Writer, decMode any, h hash.Hash, gen DecCipher) error

DecData

@Description:  decrypt data
@param r       ciphertext data read stream
@param w       the decrypted data is written to the stream
@param devMode private key data or decryption function
@param h       specify the hash verification method
@param gen     DecCipher, verify and generate a decryption algorithm based on the key
@return error

func EncData

func EncData(r io.Reader, w io.Writer, encMode any, h hash.Hash, gen EncCipher) error

EncData

@Description:  encrypted data
@param r       data source read stream
@param w       encrypted data is written to the stream
@param encMode public key or encryption function
@param h       specify the hash verification method
@param gen     EncCipher, generate key and specify encryption algorithm
@return error

func GenRsaKey

func GenRsaKey(bits int, pub, pri io.Writer) error

GenRsaKey

@Description: generate rsa public-private key pair
@param bits   generated digits
@param pub    public key write stream
@param pri    private key write stream
@return error

func RsaDecrypt

func RsaDecrypt(priKey, cipherText []byte) ([]byte, error)

RsaDecrypt

@Description:     rsa decryption logic
@param priKey     private key data
@param cipherText cipher text
@return []byte    decrypted data
@return error

func RsaEncrypt

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

RsaEncrypt

@Description:   rsa encryption logic
@param pubKey   public key data
@param origData data to be encrypted
@return []byte  return encrypted data
@return error

func WriteFull added in v1.0.7

func WriteFull(w io.Writer, b []byte) (n int, err error)

Types

type DecCipher added in v1.0.7

type DecCipher func([]byte) (any, error)

func GenDecCipher added in v1.0.7

func GenDecCipher(dec any) DecCipher

type EncCipher added in v1.0.7

type EncCipher func() ([]byte, any, error)

func GenEncCipher added in v1.0.7

func GenEncCipher(enc any) EncCipher

Jump to

Keyboard shortcuts

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