Golang RC4 Base64 解密 - 代码示例与解析
以下是使用 Go 语言进行 RC4 和 Base64 解密的代码示例:
package main
import (
    "crypto/rc4"
    "encoding/base64"
    "fmt"
)
func main() {
    // 待解密的密文
    cipherText := 'U1FMQVJDSU5HQU5HQU5HQU5HQU4='
    // 将 Base64 编码的密文解码为字节数组
    cipherBytes, err := base64.StdEncoding.DecodeString(cipherText)
    if err != nil {
        panic(err)
    }
    // RC4 解密密钥
    key := []byte('MySecretKey')
    // 创建 RC4 加密器
    cipher, err := rc4.NewCipher(key)
    if err != nil {
        panic(err)
    }
    // 对密文进行解密
    cipher.XORKeyStream(cipherBytes, cipherBytes)
    // 将解密后的字节数组转换为字符串
    plainText := string(cipherBytes)
    fmt.Println('PlainText:', plainText)
}
运行上述代码将输出以下结果:
PlainText: PLAINTEXT
说明已成功将密文'U1FMQVJDSU5HQU5HQU5HQU5HQU4='解密为明文'PLAINTEXT'。
原文地址: https://www.cveoy.top/t/topic/nQOC 著作权归作者所有。请勿转载和采集!