[PD1] changed the order of signature and content
This commit is contained in:
parent
fb7a728aa4
commit
0c9ef6122e
1 changed files with 4 additions and 2 deletions
|
@ -160,11 +160,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
|
||||
|
@ -196,7 +198,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…
Reference in a new issue