内容简介:rc4包实现了RC4加密算法,参见Bruce Schneier's Applied Cryptography。type KeySizeError intfunc (KeySizeError) Error() string
rc4包实现了RC4加密算法,参见Bruce Schneier's Applied Cryptography。
type KeySizeError int
func (KeySizeError) Error() string
type Cipher struct{...}
func NewCipher(key []byte) (*Cipher, error)
NewCipher创建并返回一个新的Cipher。参数key时RC4密钥,至少1字节,最多256字节。
func (c *Cipher) Reset()
Reset方法会清空密钥数据,以便将其数据从程序内存中清除(以免被破解)
func (c *Cipher) XORKeyStream(dst, src []byte)
XORKeyStream方法将src的数据与密钥生成的伪随机流取XOR并写入dst。dst和src可指向同一内存地址;但如果指向不同则其底层内存不可重叠。
Bugs:RC4被广泛使用,但设计上的缺陷使它很少用于较新的协议中。
package main
import (
"crypto/rc4"
"fmt"
"log"
)
func main() {
c, err := rc4.NewCipher([]byte("dsadsad"))
if err != nil {
log.Fatalln(err)
}
src := []byte("asdsad")
dst := make([]byte, len(src))
c.XORKeyStream(dst, src)
fmt.Println(string(src), string(dst))
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Data Structures and Algorithm Analysis in Java
Mark A. Weiss / Pearson / 2011-11-18 / GBP 129.99
Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course wa......一起来看看 《Data Structures and Algorithm Analysis in Java》 这本书的介绍吧!