訊息摘要、MAC(訊息認證碼)、數字簽名掃盲貼
In cryptography(密碼學), a message authentication code (MAC) is a short piece of information used to authenticate(鑑定) a message—in other words, to confirm that the message came from the stated(特定的、規定的) sender (its authenticity(可靠性、真實性))
and has not been changed in transit(在途中) (its integrity(完整性))。也就是說MAC用來保證訊息的完整性,之前的文章"
A MAC algorithm, sometimes called a keyed (cryptographic加密的) hash function (which is somewhat misleading(誤導性的), since a cryptographic hash function is only one of the possible ways to generate a MAC), accepts as input a secret key and an arbitrary(任意的)-length
message to be authenticated, and outputs a MAC (sometimes known as a tag). The MAC value protects both a message's data integrity as well as its authenticity, by allowing verifiers(核驗者) (who also possess(擁有) the secret key) to detect(探測) any changes to the
message content.也就是說:MAC是通過mac演算法+祕鑰+訊息生成的。mac演算法其實有很多種,不過最常用的還是hash演算法,比如MD5、SHA等。用hash演算法作為mac演算法,通過計算得到的mac,也就是HMAC,所以MAC與HMAC沒有太大差別。
現在我們明確下:訊息摘要與MAC的區別,訊息摘要只能保證訊息的完整性,MAC不僅能夠保證完整性,還能夠保證真實性。比如客戶端A想給服務端B傳送一條訊息,A需要把訊息內容和對應的訊息摘要都發給B;B通過同樣的摘要演算法,自然可以知道訊息是否被篡改。比如攻擊者C將A傳送的原始訊息和摘要,都篡改成新的訊息和摘要,那麼這個訊息對B來說也是完整的,只不過不是A發的。因為MAC含有祕鑰(只有A和B知道),如果A將訊息內容和MAC發給B,雖然C是仍然可以修改訊息內容和MAC,但是由於C不知道祕鑰,所以無法生成與篡改後內容匹配的MAC。
MACs differ from digital signatures(數字簽名) as MAC values are both generated and verified using the same secret key. This implies that the sender and receiver of a message must agree on the same key before initiating communications,
as is the case with symmetric encryption(對稱加密). For the same reason, MACs do not provide the property of non-repudiation(不可抵賴性) offered by signatures specifically in the case of a network-wide(網路範圍) shared secret key: any user who can verify a MAC is also
capable(有能力的) of generating MACs for other messages. In contrast(作為對比), a digital signature is generated using the private key of a key pair, which is public-key cryptography(公鑰密碼體制). Since this private key is only accessible to its holder, a digital signature
proves that a document was signed by none other than that holder. Thus, digital signatures do offer non-repudiation. However, non-repudiation can be provided by systems that securely(安全地) bind key(關鍵的) usage information to the MAC key; the same key is in the
possession of two people, but one has a copy of the key that can be used for MAC generation while the other has a copy of the key in a hardware security module that only permits MAC verification. This is commonly done in the finance industry(金融業).也就是說:MAC不能保證訊息的不可抵賴性,而數字簽名可以保證