This commit is contained in:
number571 2024-10-24 14:06:46 +07:00
parent b80e6ccf10
commit 4fdcab32db
2 changed files with 6 additions and 5 deletions

View File

@ -94,7 +94,7 @@ func (p *sClient) encryptWithParams(
data := joiner.NewBytesJoiner32([][]byte{pMsg, rand.GetBytes(pPadd)})
hash := hashing.NewHMACHasher(salt, bytes.Join(
[][]byte{pkid, pRecv.ToBytes(), data},
[][]byte{pkid, pRecv.GetHasher().ToBytes(), data},
[]byte{},
)).ToBytes()
@ -146,6 +146,7 @@ func (p *sClient) DecryptMessage(pMapPubKeys asymmetric.IMapPubKeys, pMsg []byte
data = decSlice[4]
)
// Get public key from map by pkid (hash)
sPubKey := pMapPubKeys.GetPubKey(pkid)
if sPubKey == nil {
return nil, nil, ErrDecodePublicKey
@ -154,13 +155,13 @@ func (p *sClient) DecryptMessage(pMapPubKeys asymmetric.IMapPubKeys, pMsg []byte
// Validate received hash with generated hash.
check := hashing.NewHMACHasher(salt, bytes.Join(
[][]byte{
sPubKey.ToBytes(),
p.fPrivKey.GetPubKey().ToBytes(),
sPubKey.GetHasher().ToBytes(),
p.fPrivKey.GetPubKey().GetHasher().ToBytes(),
data,
},
[]byte{},
)).ToBytes()
if bytes.Equal(check, hash) {
if !bytes.Equal(check, hash) {
return nil, nil, ErrInvalidDataHash
}

View File

@ -1 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="code lines: 12546"><title>code lines: 12546</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="57" height="20" fill="#555"/><rect x="57" width="40" height="20" fill="#4682b4"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="295" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">code lines</text><text x="295" y="140" transform="scale(.1)" fill="#fff" textLength="510">code lines</text><text aria-hidden="true" x="770" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="320">12546</text><text x="770" y="140" transform="scale(.1)" fill="#fff" textLength="320">12546</text></g></svg>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="96" height="20" role="img" aria-label="code lines: 12547"><title>code lines: 12547</title><linearGradient id="s" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><clipPath id="r"><rect width="96" height="20" rx="3" fill="#fff"/></clipPath><g clip-path="url(#r)"><rect width="57" height="20" fill="#555"/><rect x="57" width="40" height="20" fill="#4682b4"/><rect width="96" height="20" fill="url(#s)"/></g><g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="110"><text aria-hidden="true" x="295" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="510">code lines</text><text x="295" y="140" transform="scale(.1)" fill="#fff" textLength="510">code lines</text><text aria-hidden="true" x="770" y="150" fill="#010101" fill-opacity=".3" transform="scale(.1)" textLength="320">12547</text><text x="770" y="140" transform="scale(.1)" fill="#fff" textLength="320">12547</text></g></svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB