Merge branch 'main' of gon:Uni/CSI-ES-2324
This commit is contained in:
commit
7940ece7ac
2 changed files with 51 additions and 4 deletions
|
@ -174,11 +174,13 @@ func (k KeyStore) EncryptMessageContent(receiverCert *x509.Certificate, content
|
|||
|
||||
// sign the message and append the signature
|
||||
hashedContent := sha256.Sum256(content)
|
||||
// NOTE: in this case the sign then encrypt method is used
|
||||
// but should it be used over the encrypt then sign method?
|
||||
signature, err := rsa.SignPKCS1v15(nil, k.privKey, crypto.SHA256, hashedContent[:])
|
||||
if err != nil {
|
||||
log.Panicln("Could not create content signature: ", err)
|
||||
}
|
||||
content = pair(content, signature)
|
||||
content = pair(signature, content)
|
||||
ciphertext := cipher.Seal(nonce, nonce, content, nil)
|
||||
|
||||
// crypto/rand.Reader is a good source of entropy for randomizing the
|
||||
|
@ -210,7 +212,7 @@ func (k KeyStore) DecryptMessageContent(senderCert *x509.Certificate, cipherCont
|
|||
log.Panicln("Could not decrypt ciphertext: ", err)
|
||||
}
|
||||
// check signature with sender public key
|
||||
content, signature := unPair(contentAndSig)
|
||||
signature, content:= unPair(contentAndSig)
|
||||
hashedContent := sha256.Sum256(content)
|
||||
senderKey := senderCert.PublicKey.(*rsa.PublicKey)
|
||||
if err := rsa.VerifyPKCS1v15(senderKey, crypto.SHA256, hashedContent[:], signature); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue