EncryptionFile 发布 v1.0.7 版本,支持标准库 cipher 的全部 3 中加密算法接口

257 天前
 body007

项目地址: https://github.com/jan-bar/EncryptionFile

之所以更新这一版,是因为有人觉得上个版本中只用到aes cfb这种流式加密算法不安全,他们希望用更安全的aes gcm加密方式。因此我看了 go 标准库支持cipher.AEAD ,cipher.Stream ,cipher.BlockMode这三种加密接口,因此这一版本直接支持这三种接口。用户还可以自定义加解密方案,只要是上面三种接口类型就可以实现数据安全加解密。

你也可以用我内置的 EncryptionFile.GenEncCipher ,EncryptionFile.GenDecCipher 这两个方法轻松实现指定加密算法,如下所示。

当然你也可以自己写方法,只要实现cipher.AEAD ,cipher.Stream ,cipher.BlockMode这三种接口就行。

// 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))

可用学习单元测试 TestCipher,掌握这个库的用法。

601 次点击
所在节点    Go 编程语言
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/972082

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX