EncryptionFile

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

README

EncryptionFile

加密解密文件
由于需要使用流式加解密因此选用AES CFB模式
使用RSA将随机密钥加密,并将密文存入文件头部
加密文件只需要提供可执行程序和公钥
解密文件只需要提供可执行程序和私钥
即使同一个文件每次加密结果都不一样,安全系数极高
可以指定计算hash方法,最终会在末尾存入hash值

如下为加密后文件内容,为了让加解密都使用io.Reader和io.Writer,将hash放在末尾

这样不需要io.Seeker这类更新偏移,或者传入数据长度。一切都只认io.Reader返回io.EOF时结束

rsa密文长度 rsa加密aes密码后的密文 aes加密内容 数据hash值
len(rsa(password)) rsa(password) aesEnc(data) hash(data)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecData

func DecData(r io.Reader, w io.Writer, priKey []byte, h hash.Hash) error

DecData

@Description:  解密数据
@param r       密文数据读入流
@param w       解密后数据写入流
@param priKey  私钥数据
@param h       指定hash校验方法
@return error  返回错误

func EncData

func EncData(r io.Reader, w io.Writer, pubKey []byte, h hash.Hash) error

EncData

@Description: 加密数据
@param r      数据来源读出流
@param w      加密数据写入流
@param pubKey 公钥数据
@param h      指定hash校验方法
@return error 返回错误

func GenRsaKey

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

GenRsaKey

@Description: 生成rsa公私钥对
@param bits   生成位数
@param pub    公钥写入流
@param pri    私钥写入流
@return error 返回错误

func RsaDecrypt

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

RsaDecrypt

@Description:     rsa解密逻辑
@param priKey     私钥数据
@param cipherText 密文
@return []byte    解密后数据
@return error     返回错误

func RsaEncrypt

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

RsaEncrypt

@Description:   rsa加密逻辑
@param pubKey    公钥数据
@param origData  待加密数据
@return []byte   返回加密后数据
@return error    返回错误

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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