Skip to content

Commit

Permalink
add Passphrase()
Browse files Browse the repository at this point in the history
  • Loading branch information
aine-etke committed Oct 16, 2024
1 parent 91f2e44 commit d39bde5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions password.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package secgen

import (
"crypto/rand"
"crypto/sha512"
"encoding/base64"
"encoding/hex"
"math/big"
Expand All @@ -23,6 +24,12 @@ func Password(length int) string {
return password.String()
}

// Passphrase generates secure passphrase, based on shared secret and salt
func Passphrase(sharedSecret, salt string) string {
hash := sha512.Sum512([]byte(sharedSecret + salt))
return base64.StdEncoding.EncodeToString(hash[:])[:64]
}

// Base64Bytes generates secure bytes with the given length and returns it as a base64 string
func Base64Bytes(length int) string {
randomBytes := make([]byte, length)
Expand Down

0 comments on commit d39bde5

Please sign in to comment.