init
This commit is contained in:
commit
23c7133fa9
33 files changed
+2896
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package keymgr
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// charset avoids visually ambiguous characters (0/O, 1/l/I) since this
|
||||
// password is normally read aloud or typed by hand on the recipient side.
|
||||
const passwordCharset = "23456789ABCDEFGHJKMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz"
|
||||
|
||||
// GenerateBatchPassword returns a cryptographically random password shared
|
||||
// by every archive produced in one export batch. It is shown to the admin
|
||||
// exactly once (see the export result screen) and must be relayed to each
|
||||
// recipient over a channel separate from the archive itself.
|
||||
func GenerateBatchPassword(length int) (string, error) {
|
||||
if length <= 0 {
|
||||
length = 20
|
||||
}
|
||||
out := make([]byte, length)
|
||||
max := big.NewInt(int64(len(passwordCharset)))
|
||||
for i := range out {
|
||||
n, err := rand.Int(rand.Reader, max)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
out[i] = passwordCharset[n.Int64()]
|
||||
}
|
||||
return string(out), nil
|
||||
}
|
||||
Reference in new issue
Block a user