-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt.go
43 lines (38 loc) · 1.25 KB
/
encrypt.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
package gocrypto
import "crypto/rsa"
// Encrypt interface for encrption.
type Encrypt interface {
// Sign data.
Sign(data []byte) ([]byte, error)
// ValidateSignature validates the signature.
ValidateSignature(data []byte, signature []byte) (bool, error)
// Encrypt data.
Encrypt(data []byte) ([]byte, error)
// Decrypt data.
Decrypt(data []byte) ([]byte, error)
// EncryptBase64 encrypt data and encode it to base64 string.
EncryptBase64(data []byte) (string, error)
// DecryptBase64 decode base64 string and decrypt it.
DecryptBase64(encrypted string) ([]byte, error)
}
// NewSymmetric creates a new symmetric encryption driver.
func NewSymmetric(key SimpleKey, signer HashingAlgo) Encrypt {
driver := new(symmetricDriver)
driver.key = key
driver.signer = signer
return driver
}
// NewAsymmetric creates a new asymmetric encryption driver.
func NewAsymmetric(key RSAKey, signer HashingAlgo) Encrypt {
driver := new(asymmetricDriver)
driver.key = &key
driver.signer = signer
return driver
}
// NewAsymmetricClient creates a new asymmetric encryption driver from public key.
func NewAsymmetricClient(public *rsa.PublicKey, signer HashingAlgo) Encrypt {
driver := new(asymmetricDriver)
driver.publicKey = public
driver.signer = signer
return driver
}