Standard library / crypto/rc4

crypto/rc4.NewCipher()

Obsolete cipher; never use for new security systems. Accepts keys of 1–256 bytes and creates stateful stream cipher. Public fixed key for an isolated test vector only; do not use it to protect real data. Expected stdout: '2\n'.

Formal Syntax & Structure

go syntaxgo
func NewCipher(key []byte) (*Cipher, error)

Parameters & Attributes

NameTypeDescription
key[]byteKey bytes of a supported length.

Return Value

(*Cipher, error)

Cipher instance, or an error for an invalid key length.

Working Example

Example Snippetgo
package main
import (  "crypto/rc4"  "fmt")
func main() {  // Historical interoperability demonstration only. Never deploy this cipher/mode.  b := must(rc4.NewCipher(make([]byte, 5)))  dst := make([]byte, 2)  b.XORKeyStream(dst, []byte("Go"))  fmt.Println(len(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)  }}
Go Reference