十小时开源了一个加密算法仓库,功能强大,后端开发人员狂喜!

写在前面

昨晚上睡觉前我就在想能不能把多个加密算法集成到一个库中,方便开发者调用,说干就干,今天肝了一天,中午直接吃的外卖哈哈哈哈,终于把仓库开源了,欢迎各位Go开发者StarFork!

仓库地址

go-crypto-guardhttps://github.com/palp1tate/go-crypto-guard

介绍

该存储库包含一个用 Go 编写的综合密码哈希库。该库支持多种哈希算法,包括 PBKDF2(使用 SHA1、SHA256、SHA384、SHA512 和 MD5)、Bcrypt、Scrypt、Argon2、HMAC、Blake2b 和 Blake2s。它允许自定义盐长度、迭代、密钥长度和算法选择。该开源项目旨在为开发人员提供用于安全密码存储和验证的多功能工具。尤其是后端开发人员,在实现登录注册业务中通常会遇到密码加密和验证的问题,该库可以很好的解决这个问题,功能强大。为了更方便的想使用什么算法就使用什么算法(含加盐),于是这个仓库就横空出世了。

支持的算法:

password的格式与Django内置的加密算法格式相同:

go 复制代码
<algorithm>$<iterations>$<salt>$<hash>

安装

bash 复制代码
go get github.com/palp1tate/go-crypto-guard 

用法

下面提供了一些用法示例:

go 复制代码
package main

import (
	"fmt"
	"github.com/palp1tate/go-crypto-guard"
)

func main() {
	originPwd := "123456"
	options := pwd.Options{
		SaltLen:    16,
		KeyLen:     32,
		Iterations: 100,
		Algorithm:  pwd.SHA512,
	}
	encodedPwd, err := pwd.Generate(originPwd, &options)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("Encoded password:", encodedPwd)

	if ok, err := pwd.Verify(originPwd, encodedPwd); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Verify result:", ok)
	}
}

对于SHA512、SHA256、SHA1、SHA384、Md5、Argon2,可以填写全部参数,也可以不完全填写。但对于其他算法,它们不需要那么多参数,你甚至可以只用指定具体的算法:

go 复制代码
//Bcrypt
options := pwd.Options{
		Algorithm: pwd.Bcrypt,
	}

//HMAC
options := pwd.Options{
		Algorithm: pwd.HMAC,
	}

//...

Options定义用于自定义密码散列过程的参数。每个字段都有一个默认值,即使您不传递参数也是如此。

go 复制代码
// Fields:
//   - SaltLen: Length of the salt to be generated for password hashing.
//   - Iterations: Number of iterations to apply during the hashing process.
//   - KeyLen: Length of the derived key produced by the hashing algorithm.
//   - Algorithm: The specific hashing algorithm to be used for password hashing.
type Options struct {
	SaltLen    int    //  Defaults to 16.
	Iterations int    //  Defaults to 50.
	KeyLen     int    //  Defaults to 32.
	Algorithm  string //  Defaults to "SHA512".
}

未来的计划

计划在未来的版本中加入更多的哈希算法,以满足不同的场景和需求。以下是可能考虑的一些算法:

也有考虑出一个Python版本。

请注意,这只是一个计划,可能会根据项目需求和社区反馈进行更改。将通过 GitHub 存储库向用户通报任何更改或添加的最新情况。

相关推荐
冬奇Lab7 分钟前
Code Agent 解剖(17):AgentTeams——消息怎么在 agent 之间传递?
人工智能·开源
冬奇Lab7 分钟前
一天一个开源项目(第205篇):PenguinHarness - 让 AI 来构建 AI
人工智能·开源·资讯
pnoker3 小时前
IoT DC3 参与指南:文档、Demo、CLI 与贡献路径
物联网·开源·开源社区·agpl·贡献指南
m4Rk_3 小时前
【论文阅读】Agent 记忆机制(57):MemSearch-o1——从查询词元生长证据,重组 Deep Search 记忆路径
论文阅读·人工智能·学习·开源·github
Crazy_MT4 小时前
不越狱,iPhone 为什么也能安装任意 IPA?聊聊 iLoader、SideStore 和 LiveContainer 的原理
ios·开源
ApacheSeaTunnel5 小时前
用 Apache SeaTunnel 同步 DynamoDB 到 Redis,一个配置文件就够
redis·开源·seatunnel·数据同步·dynamodb
白鲸开源7 小时前
DolphinScheduler 挂了你不知道?Prometheus + Grafana 监控兜底方案,亲测可用
开源·grafana·监控
小小龙学IT7 小时前
ONNX Runtime 开源 AI 推理引擎深度解析:从模型部署到边缘 AI 加速的全栈实战
c++·人工智能·开源