-
-
Notifications
You must be signed in to change notification settings - Fork 59
/
hash.go
37 lines (32 loc) · 968 Bytes
/
hash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package faker
import (
"crypto/md5"
"crypto/sha256"
"crypto/sha512"
"fmt"
)
// Hash is the faker struct for Hashing Functions
type Hash struct {
Faker *Faker
}
// SHA256 returns a random sha256 based random hashed string
func (hash Hash) SHA256() string {
hashFunction := sha256.New()
randomString := hash.Faker.Lorem().Word()
hashFunction.Write([]byte(randomString))
return fmt.Sprintf("%x", string(hashFunction.Sum(nil)))
}
// SHA512 returns a random sha512 based random hashed string
func (hash Hash) SHA512() string {
hashFunction := sha512.New()
randomString := hash.Faker.Lorem().Word()
hashFunction.Write([]byte(randomString))
return fmt.Sprintf("%x", string(hashFunction.Sum(nil)))
}
// MD5 returns a random MD5 based random hashed string
func (hash Hash) MD5() string {
hashFunction := md5.New()
randomString := hash.Faker.Lorem().Word()
hashFunction.Write([]byte(randomString))
return fmt.Sprintf("%x", string(hashFunction.Sum(nil)))
}