当前位置: 首页>>代码示例>>Golang>>正文


Golang rc4.Cipher类代码示例

本文整理汇总了Golang中crypto/rc4.Cipher的典型用法代码示例。如果您正苦于以下问题:Golang Cipher类的具体用法?Golang Cipher怎么用?Golang Cipher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cipher类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: read_stego

func read_stego(img io.Reader, secret string, out io.Writer) {

	// see if encryption is used or not
	var encrypt bool = false
	var crypt *rc4.Cipher

	if secret != "" {
		encrypt = true
		var err error
		crypt, err = rc4.NewCipher([]byte(secret))
		if err != nil {
			panic(err)
		}

		// when the function is finished, zero the keyspace
		defer crypt.Reset()
	}

	// get a buffer to read data from the image
	buf := make([]byte, 128)

	// create the stego img reader to read the data
	stegoReader, err := stegoimg.NewStegoImgReader(img)
	if err != nil {
		panic(err)
	}

	// read and decrypt the data
	for {

		// read the new data block
		n, err := stegoReader.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}

		// break if no data was read
		if n == 0 {
			break
		}

		// optionally decrypt
		if encrypt {
			crypt.XORKeyStream(buf[:n], buf[:n])
		}

		// write to the stego writer
		_, writeErr := out.Write(buf[:n])
		if writeErr != nil {
			panic(writeErr)
		}

		// break if that's the end of the data
		if err == io.EOF {
			break
		}
	}

	return
}
开发者ID:AndrewBurian,项目名称:stegotool,代码行数:60,代码来源:read.go

示例2: uValueGen

func (p *protectType) uValueGen() (v []byte) {
	var c *rc4.Cipher
	c, _ = rc4.NewCipher(p.encryptionKey)
	cap := len(p.padding)
	v = make([]byte, cap, cap)
	c.XORKeyStream(v, p.padding)
	return
}
开发者ID:movedispatch,项目名称:gofpdf,代码行数:8,代码来源:protect.go

示例3: oValueGen

func oValueGen(userPass, ownerPass []byte) (v []byte) {
	var c *rc4.Cipher
	tmp := md5.Sum(ownerPass)
	c, _ = rc4.NewCipher(tmp[0:5])
	cap := len(userPass)
	v = make([]byte, cap, cap)
	c.XORKeyStream(v, userPass)
	return
}
开发者ID:movedispatch,项目名称:gofpdf,代码行数:9,代码来源:protect.go

示例4: rc4

func rc4(cipher *rc4P.Cipher, ciphertext []byte) []byte {
	result := make([]byte, len(ciphertext))
	cipher.XORKeyStream(result, ciphertext)
	return result
}
开发者ID:2012781508623add,项目名称:git-lfs,代码行数:5,代码来源:crypto.go

示例5: write_stego

func write_stego(img, data io.Reader, secret string, out io.Writer) {

	// see if encryption is used or not
	var encrypt bool = false
	var crypt *rc4.Cipher

	if secret != "" {
		encrypt = true
		var err error
		crypt, err = rc4.NewCipher([]byte(secret))
		if err != nil {
			panic(err)
		}

		// when the function is finished, zero the keyspace
		defer crypt.Reset()
	}

	// get a buffer to read data from the data
	buf := make([]byte, 128)

	// create the new stego img writer to encode the data
	stegoWriter, err := stegoimg.NewStegoImgWriter(img, out)
	if err != nil {
		panic(err)
	}
	defer stegoWriter.Close()

	// read and encode the data
	for {

		// read the new data block
		n, err := data.Read(buf)
		if err != nil && err != io.EOF {
			panic(err)
		}

		// break if no data was read
		if n == 0 {
			break
		}

		// optionally encrypt
		if encrypt {
			crypt.XORKeyStream(buf[:n], buf[:n])
		}

		// write to the stego writer
		_, writeErr := stegoWriter.Write(buf[:n])

		// check if the image filled up
		if writeErr == stegoimg.ImageFullError && err != io.EOF {
			fmt.Println("Image full before data finished")
			break
		}

		// break if that's the end of the data
		if err == io.EOF {
			break
		}
	}

	// finished creating the image
	return
}
开发者ID:AndrewBurian,项目名称:stegotool,代码行数:65,代码来源:write.go

示例6: makeSeedMessage

func makeSeedMessage(maxPadding int, seed []byte, clientToServerCipher *rc4.Cipher) ([]byte, error) {
	// paddingLength is integer in range [0, maxPadding]
	paddingLength, err := MakeSecureRandomInt(maxPadding + 1)
	if err != nil {
		return nil, ContextError(err)
	}
	padding, err := MakeSecureRandomBytes(paddingLength)
	if err != nil {
		return nil, ContextError(err)
	}
	buffer := new(bytes.Buffer)
	err = binary.Write(buffer, binary.BigEndian, seed)
	if err != nil {
		return nil, ContextError(err)
	}
	err = binary.Write(buffer, binary.BigEndian, uint32(OBFUSCATE_MAGIC_VALUE))
	if err != nil {
		return nil, ContextError(err)
	}
	err = binary.Write(buffer, binary.BigEndian, uint32(paddingLength))
	if err != nil {
		return nil, ContextError(err)
	}
	err = binary.Write(buffer, binary.BigEndian, padding)
	if err != nil {
		return nil, ContextError(err)
	}
	seedMessage := buffer.Bytes()
	clientToServerCipher.XORKeyStream(seedMessage[len(seed):], seedMessage[len(seed):])
	return seedMessage, nil
}
开发者ID:yangguangyu,项目名称:psiphon-tunnel-core,代码行数:31,代码来源:obfuscator.go


注:本文中的crypto/rc4.Cipher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。