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

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

如何使用加密/rc4

如何使用加密/rc4

Go
手掌心 2022-06-27 11:07:21
我正在嘗試使用 RC4 加密/解密 Go 中的一些數(shù)據(jù)。我發(fā)現(xiàn) Go 在 crypto/rc4 包中提供了 rc4 算法。我嘗試使用包加密/解密數(shù)據(jù),但密文和解密的明文不是我所期望的。我與類似這樣的 RC4 在線工具進(jìn)行了比較,但我確信 Go 的 rc4 包有一些問(wèn)題。因?yàn)樵谖矣?Go rc4 加密明文并解密密文后,解密的明文'不是我加密的。我應(yīng)該找到其他圖書館嗎?我運(yùn)行的代碼是這樣的。package mainimport (    "crypto/rc4"    "fmt"    "log")func main() {    c, err := rc4.NewCipher([]byte("dsadsad"))    if err != nil {        log.Fatalln(err)    }    src := []byte("asdsad")    dst := make([]byte, len(src))    fmt.Println("Plaintext: ", src)    c.XORKeyStream(dst, src)    c.XORKeyStream(src, dst)    fmt.Println("Ciphertext: ", dst)    fmt.Println("Plaintext': ", src)}輸出是這樣的Plaintext:  [97 115 100 115 97 100]Ciphertext:  [98 41 227 117 93 79]Plaintext':  [111 154 128 112 250 88]
查看完整描述

1 回答

?
繁華開(kāi)滿天機(jī)

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

您不能使用相同的 RC4 密碼來(lái)加密然后解密,因?yàn)樗哂袃?nèi)部狀態(tài)。


構(gòu)造一個(gè)具有相同密鑰的新密碼來(lái)解密:


// ENCRYPT

c, err := rc4.NewCipher([]byte("dsadsad"))

if err != nil {

    log.Fatalln(err)

}

src := []byte("asdsad")

fmt.Println("Plaintext: ", src)


dst := make([]byte, len(src))

c.XORKeyStream(dst, src)

fmt.Println("Ciphertext: ", dst)


// DECRYPT

c2, err := rc4.NewCipher([]byte("dsadsad"))

if err != nil {

    log.Fatalln(err)

}

src2 := make([]byte, len(dst))

c2.XORKeyStream(src2, dst)

fmt.Println("Plaintext': ", src2)

這將輸出(在Go Playground上嘗試):


Plaintext:  [97 115 100 115 97 100]

Ciphertext:  [98 41 227 117 93 79]

Plaintext':  [97 115 100 115 97 100]

但正如包文檔所述:


RC4 已被密碼破解,不應(yīng)用于安全應(yīng)用程序。


因此,請(qǐng)使用另一種更安全的算法,例如crypto/aes.


查看完整回答
反對(duì) 回復(fù) 2022-06-27
  • 1 回答
  • 0 關(guān)注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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