-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencodePrivateKey.go
More file actions
44 lines (38 loc) · 1.12 KB
/
Copy pathencodePrivateKey.go
File metadata and controls
44 lines (38 loc) · 1.12 KB
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
38
39
40
41
42
43
44
package main
import (
"github.com/ProtonMail/gopenpgp/v2/crypto"
)
type Keys struct {
Public string
EncodedPrivate string
Password string
}
func GetNewPGPKeysWithSHA512PW(username string, password string, email string) (*Keys, error) {
return generatePGPKeys(username, password, email)
}
func GetNewPGPKeysWithPlainTextPW(username, password string, email string) (*Keys, error) {
hashedPassword := SHA512HashEncode(password)
return generatePGPKeys(username, hashedPassword, email)
}
func generatePGPKeys(username string, password string, email string) (*Keys, error) {
hashString := password[32:]
ecKey, err := crypto.GenerateKey(username, email, "x25519", 0)
locked, err := ecKey.Lock([]byte(hashString))
if err != nil {
return nil, err
}
publicKey, err := ecKey.GetArmoredPublicKey()
if err != nil {
return nil, err
}
lockedPrivateKey, err := locked.Armor()
if err != nil {
return nil, err
}
return &Keys{
Public: publicKey,
EncodedPrivate: lockedPrivateKey,
///todo: remove the password as we dont need to be handing it about it was here for testing.
Password: password,
}, nil
}