golang中crypto/rc4包

栏目: Go · 发布时间: 6年前

内容简介: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))
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

An Introduction to Genetic Algorithms

An Introduction to Genetic Algorithms

Melanie Mitchell / MIT Press / 1998-2-6 / USD 45.00

Genetic algorithms have been used in science and engineering as adaptive algorithms for solving practical problems and as computational models of natural evolutionary systems. This brief, accessible i......一起来看看 《An Introduction to Genetic Algorithms》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

html转js在线工具
html转js在线工具

html转js在线工具