Merge branch 'main' of gon:Uni/CSI-ES-2324
This commit is contained in:
commit
cfe9f3c7b3
1 changed files with 30 additions and 7 deletions
|
@ -178,7 +178,30 @@ func (k KeyStore) EncryptMessageContent(receiverCert *x509.Certificate, content
|
|||
}
|
||||
|
||||
func (k KeyStore) DecryptMessageContent(senderCert *x509.Certificate, cipherContent []byte) []byte {
|
||||
return nil
|
||||
encryptedDataKey, encryptedMsg := unPair(cipherContent)
|
||||
dataKey, err := rsa.DecryptOAEP(sha256.New(), rand.Reader, k.GetPrivKey(), encryptedDataKey, nil)
|
||||
if err != nil {
|
||||
log.Panicln("Could not decrypt dataKey: ", err)
|
||||
}
|
||||
// decrypt ciphertext
|
||||
cipher, err := chacha20poly1305.New(dataKey)
|
||||
if err != nil {
|
||||
log.Panicln("Could not create cipher: ", err)
|
||||
}
|
||||
|
||||
nonce, ciphertext := encryptedMsg[:cipher.NonceSize()], encryptedMsg[cipher.NonceSize():]
|
||||
contentAndSig, err := cipher.Open(nil, nonce, ciphertext, nil)
|
||||
if err != nil {
|
||||
log.Panicln("Could not decrypt ciphertext: ", err)
|
||||
}
|
||||
// check signature with sender public key
|
||||
content, signature := unPair(contentAndSig)
|
||||
hashedContent := sha256.Sum256(content)
|
||||
senderKey := senderCert.PublicKey.(*rsa.PublicKey)
|
||||
if err := rsa.VerifyPKCS1v15(senderKey, crypto.SHA256, hashedContent[:], signature); err != nil {
|
||||
log.Panicln("Signature is not valid: ", err)
|
||||
}
|
||||
return content
|
||||
}
|
||||
|
||||
func pair(l []byte, r []byte) []byte {
|
||||
|
|
Loading…
Add table
Reference in a new issue