package main
import (
"crypto/rc4"
"fmt"
)
func main() {
key := []byte("RC4_key")
plaintext := []byte("data_should_be_array_of_bytes")
// encryption
ciphertext := make([]byte, len(plaintext))
fmt.Printf("plaintext:%s \n", plaintext)
cipher1, _ := rc4.NewCipher(key)
cipher1.XORKeyStream(ciphertext, plaintext)
fmt.Printf("ciphertext:%s \n", ciphertext)
// decryption
plaintext_dec := make([]byte, len(ciphertext))
cipher2, _ := rc4.NewCipher(key) // remember to new a cipher for the same initial
cipher2.XORKeyStream(plaintext_dec, ciphertext)
fmt.Printf("plaintext decrypted:%s \n", plaintext_dec)
}
ceshi 一会就删除
最新推荐文章于 2024-09-24 23:38:45 发布