service/vendor/github.com/forgoer/openssl/key.go

22 lines
310 B
Go
Raw Permalink Normal View History

2024-06-18 17:10:42 +08:00
package openssl
import (
"crypto/sha1"
)
func KeyGenerator(src []byte, blockSize int) []byte {
hashs := SHA1(SHA1(src))
maxLen := len(hashs)
if blockSize > maxLen {
return src
}
return hashs[0:blockSize]
}
func SHA1(data []byte) []byte {
h := sha1.New()
_, _ = h.Write(data)
return h.Sum(nil)
}