-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto.go
63 lines (48 loc) · 1.34 KB
/
crypto.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package crypto
import (
"fmt"
"time"
"github.com/multiverse-os/levelup/crypto/argon2"
)
//GenerateKey(seed string) Keypair
//GenerateRandomKey() Keypair
type OTPType int
const (
Time OTPType = iota
HMAC
)
type CryptographicKey interface {
GenerateChildKey() Keypair
// NOTE: Derive a SSH, Bitcoin or other key deterministically (incrementable)
// from any key type, for example: Use a PGP key to generate your SSH
// keys on all your remote machines.
DeriveKeypair(algorithm Algorithm) Keypair
OneTimePassword(otpType OTPType) []byte
ExpiresAt(expiresAt time.Time) Keypair
Name(name string) Keypair
ContactURI(contact string) Keypair
Password(symmetricEncryption string) Keypair
Algorithm() string
Encrypt(input []byte) ([]byte, error)
Decrypt(input []byte) ([]byte, error)
Sign(input []byte) ([]byte, error)
VerifySignature(input []byte) (bool, error)
SplitKey() []KeyPart
AssembleKey(keyParts ...KeyPart) Keypair
GenerateToken(expiresAt time.Time) Token
GenerateCertificate(expiresAt time.Time) Certificate
}
func GenerateKey(algorithm AlgorithmType, seed []byte) (Keypair, error) {
switch algorithm {
case Argon2:
keypair := Keypair{
Algorithm: Algorithm{
Type: algorithm,
Params: argon2.DefaultParams(),
},
}
return keypair
default:
return Keypair{}, fmt.Errorf("invalid algorithm")
}
}