企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# package rc4 `import "crypto/rc4"` rc4包实现了RC4加密算法,参见Bruce Schneier's Applied Cryptography。 ## Index * [type KeySizeError](#KeySizeError) * [func (k KeySizeError) Error() string](#KeySizeError.Error) * [type Cipher](#Cipher) * [func NewCipher(key []byte) (\*Cipher, error)](#NewCipher) * [func (c \*Cipher) Reset()](#Cipher.Reset) * [func (c \*Cipher) XORKeyStream(dst, src []byte)](#Cipher.XORKeyStream) ## type [KeySizeError](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L20 "View Source") ``` type KeySizeError int ``` ### func (KeySizeError) [Error](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L22 "View Source") ``` func (k KeySizeError) Error() string ``` ## type [Cipher](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L15 "View Source") ``` type Cipher struct { // 内含隐藏或非导出字段 } ``` Cipher是一个使用特定密钥的RC4实例,本类型实现了cipher.Stream接口。 ### func [NewCipher](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L28 "View Source") ``` func NewCipher(key []byte) (*Cipher, error) ``` NewCipher创建并返回一个新的Cipher。参数key是RC4密钥,至少1字节,最多256字节。 ### func (\*Cipher) [Reset](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L47 "View Source") ``` func (c *Cipher) Reset() ``` Reset方法会清空密钥数据,以便将其数据从程序内存中清除(以免被破解) ### func (\*Cipher) [XORKeyStream](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4_asm.go#L13 "View Source") ``` func (c *Cipher) XORKeyStream(dst, src []byte) ``` XORKeyStream方法将src的数据与秘钥生成的伪随机位流取XOR并写入dst。dst和src可指向同一内存地址;但如果指向不同则其底层内存不可重叠。 ## Bugs [☞](https://github.com/golang/go/blob/master/src/crypto/rc4/rc4.go#L9 "View Source") RC4被广泛使用,但设计上的缺陷使它很少用于较新的协议中。