-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_rsa.go
54 lines (48 loc) · 1.13 KB
/
message_rsa.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
package emp
import "crypto"
// RSAMessage represents RSA encrypted ET message.
// It is composition type of base AsymmetricMessage struct
type RSAMessage struct {
AsymmetricMessage
}
// NewRsaSha256Message returns new unencrypted message
func NewRsaSha256Message(text string) *RSAMessage {
return &RSAMessage{
AsymmetricMessage{
EncMessage: EncMessage{
Algorithm: AlgRsaSha256,
},
rawMessage: []byte(text),
hash: crypto.SHA256,
},
}
}
// NewRsaSha512Message returns new unencrypted message
func NewRsaSha512Message(text string) *RSAMessage {
return &RSAMessage{
AsymmetricMessage{
EncMessage: EncMessage{
Algorithm: AlgRsaSha512,
},
rawMessage: []byte(text),
hash: crypto.SHA512,
},
}
}
// LoadRsaMessage populates RSAMessage struct with given emsg data
func LoadRsaMessage(emsg MessageEncrypter) *RSAMessage {
hash := crypto.SHA256
if emsg.Alg() == AlgRsaSha512 {
hash = crypto.SHA512
}
return &RSAMessage{
AsymmetricMessage{
EncMessage: EncMessage{
Algorithm: emsg.Alg(),
Message: emsg.EncryptedMessage(),
Sig: emsg.Signature(),
},
hash: hash,
},
}
}