Standard library / crypto/rc4
crypto/rc4.Cipher.XORKeyStream()
Legacy-only RC4. XORs successive keystream bytes with src; dst must be at least as long, with exact or no overlap. Same key/initial state reverses the transformation. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: 'bbf316e8d940af0ad3\n'.
Formal Syntax & Structure
go syntaxgo
func (c *Cipher) XORKeyStream(dst, src []byte)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| dst | []byte | Output buffer. |
| src | []byte | Input bytes. |
Working Example
Example Snippetgo
package main
import ( "crypto/rc4" "fmt")
func main() { // Historical interoperability demonstration only. Never deploy this cipher/mode. c := must(rc4.NewCipher([]byte("Key"))) dst := make([]byte, 9) c.XORKeyStream(dst, []byte("Plaintext")) fmt.Printf("%x\n", dst)}func must[T any](v T, e error) T { if e != nil { panic(e) } return v}func check(e error) { if e != nil { panic(e) }}