第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Golang AES StreamReader 加密 - 示例省略了對(duì)加密數(shù)據(jù)的任何身份驗(yàn)證

Golang AES StreamReader 加密 - 示例省略了對(duì)加密數(shù)據(jù)的任何身份驗(yàn)證

Go
守著一只汪 2021-10-04 16:50:43
最后,我在 StackOverflow 上發(fā)布了我的第一個(gè)問(wèn)題。我已經(jīng)使用這個(gè)網(wǎng)站多年了,我總能找到對(duì)我所有問(wèn)題的很好的答案:)我正在實(shí)現(xiàn)一個(gè)基于官方 Golang 密碼示例的文件加密后臺(tái)守護(hù)程序:func ExampleStreamReader() {    key := []byte("example key 1234")    inFile, err := os.Open("encrypted-file")    if err != nil {        panic(err)    }    defer inFile.Close()    block, err := aes.NewCipher(key)    if err != nil {        panic(err)    }    // If the key is unique for each ciphertext, then it's ok to use a zero    // IV.    var iv [aes.BlockSize]byte    stream := cipher.NewOFB(block, iv[:])    outFile, err := os.OpenFile("decrypted-file", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)    if err != nil {        panic(err)    }    defer outFile.Close()    reader := &cipher.StreamReader{S: stream, R: inFile}    // Copy the input file to the output file, decrypting as we go.    if _, err := io.Copy(outFile, reader); err != nil {        panic(err)    }    // Note that this example is simplistic in that it omits any    // authentication of the encrypted data. If you were actually to use    // StreamReader in this manner, an attacker could flip arbitrary bits in    // the output.}func ExampleStreamWriter() {    key := []byte("example key 1234")    inFile, err := os.Open("plaintext-file")    if err != nil {        panic(err)    }    defer inFile.Close()    block, err := aes.NewCipher(key)    if err != nil {        panic(err)    }    // If the key is unique for each ciphertext, then it's ok to use a zero    // IV.    var iv [aes.BlockSize]byte    stream := cipher.NewOFB(block, iv[:])    outFile, err := os.OpenFile("encrypted-file", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)    if err != nil {        panic(err)    }    defer outFile.Close()    writer := &cipher.StreamWriter{S: stream, W: outFile}    // Copy the input file to the output file, encrypting as we go.    if _, err := io.Copy(writer, inFile); err != nil {        panic(err)    }以下引用是什么意思。關(guān)于提供安全加密和解密我應(yīng)該注意什么?請(qǐng)注意,此示例很簡(jiǎn)單,因?yàn)樗÷粤藢?duì)加密數(shù)據(jù)的任何身份驗(yàn)證。如果您真的以這種方式使用 StreamReader,攻擊者可以翻轉(zhuǎn)輸出中的任意位。謝謝!
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

來(lái)自維基百科:


分組密碼模式 ECB、CBC、OFB、CFB、CTR 和 XTS 提供機(jī)密性,但它們不能防止意外修改或惡意篡改。


一個(gè)很好的解釋可以在這里找到:https : //security.stackexchange.com/a/33576。


Go 支持其他支持完整性和身份驗(yàn)證檢查的模式。正如 rossum 所說(shuō),您可以使用GCM或CCM。您可以在godoc.org上找到很多示例。例如 HashiCorp 的成員列表庫(kù)。


另一個(gè)庫(kù)值得檢查是NaCl的端口golang.org/x/crypto/nacl:


func Open(out []byte, box []byte, nonce *[24]byte, key *[32]byte) ([]byte, bool)

func Seal(out, message []byte, nonce *[24]byte, key *[32]byte) []byte

如果您正在處理小消息,這個(gè) API 可能會(huì)更容易使用。


查看完整回答
反對(duì) 回復(fù) 2021-10-04
  • 1 回答
  • 0 關(guān)注
  • 267 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)