小编Pol*_*l4b的帖子

如何使用加密/rc4

我正在尝试使用 RC4 在 Go 中加密/解密一些数据。我发现 Go 在 crypto/rc4 包中提供了 rc4 算法。我尝试使用该包加密/解密数据,但密文和解密的明文不是我所期望的。

我RC4在线工具像比较这个,但我敢肯定,Go的RC4包有一些问题。因为在我用 Go rc4 加密明文并解密密文后,解密的明文'不是我加密的。我应该找其他图书馆吗?

我运行的代码是这样的。

package main

import (
    "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)
}
Run Code Online (Sandbox Code Playgroud)

输出是这样的

Plaintext:  [97 115 100 115 97 100]
Ciphertext:  [98 41 227 117 93 79]
Plaintext':  [111 154 128 …
Run Code Online (Sandbox Code Playgroud)

encryption go rc4-cipher

0
推荐指数
1
解决办法
472
查看次数

标签 统计

encryption ×1

go ×1

rc4-cipher ×1