開發(fā)公司起名seo網(wǎng)站快速排名
寫在前面
昨晚上睡覺前我就在想能不能把多個(gè)加密算法集成到一個(gè)庫中,方便開發(fā)者調(diào)用,說干就干,今天肝了一天,中午直接吃的外賣哈哈哈哈,終于把倉庫開源了,歡迎各位Go
開發(fā)者Star
和Fork
!
倉庫地址
go-crypto-guard :https://github.com/palp1tate/go-crypto-guard
介紹
該存儲(chǔ)庫包含一個(gè)用 Go 編寫的綜合密碼哈希庫。該庫支持多種哈希算法,包括 PBKDF2(使用 SHA1、SHA256、SHA384、SHA512 和 MD5)、Bcrypt、Scrypt、Argon2、HMAC、Blake2b 和 Blake2s。它允許自定義鹽長(zhǎng)度、迭代、密鑰長(zhǎng)度和算法選擇。該開源項(xiàng)目旨在為開發(fā)人員提供用于安全密碼存儲(chǔ)和驗(yàn)證的多功能工具。尤其是后端開發(fā)人員,在實(shí)現(xiàn)登錄注冊(cè)業(yè)務(wù)中通常會(huì)遇到密碼加密和驗(yàn)證的問題,該庫可以很好的解決這個(gè)問題,功能強(qiáng)大。為了更方便的想使用什么算法就使用什么算法(含加鹽),于是這個(gè)倉庫就橫空出世了。
支持的算法:
- SHA512
- SHA384
- SHA256
- SHA1
- Md5
- HMAC
- Argon2
- Bcrypt
- Scrypt
- Blake2b
- Blake2s
password的格式與Django內(nèi)置的加密算法格式相同:
<algorithm>$<iterations>$<salt>$<hash>
安裝
go get github.com/palp1tate/go-crypto-guard
用法
下面提供了一些用法示例:
package mainimport ("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)}
}
對(duì)于SHA512、SHA256、SHA1、SHA384、Md5、Argon2,可以填寫全部參數(shù),也可以不完全填寫。但對(duì)于其他算法,它們不需要那么多參數(shù),你甚至可以只用指定具體的算法:
//Bcrypt
options := pwd.Options{Algorithm: pwd.Bcrypt,}//HMAC
options := pwd.Options{Algorithm: pwd.HMAC,}//...
Options
定義用于自定義密碼散列過程的參數(shù)。每個(gè)字段都有一個(gè)默認(rèn)值,即使您不傳遞參數(shù)也是如此。
// 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".
}
未來的計(jì)劃
計(jì)劃在未來的版本中加入更多的哈希算法,以滿足不同的場(chǎng)景和需求。以下是可能考慮的一些算法:
- RSA
- DES
- AES
- ……
也有考慮出一個(gè)Python
版本。
請(qǐng)注意,這只是一個(gè)計(jì)劃,可能會(huì)根據(jù)項(xiàng)目需求和社區(qū)反饋進(jìn)行更改。將通過 GitHub 存儲(chǔ)庫向用戶通報(bào)任何更改或添加的最新情況。