Пример #1
0
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
}
Пример #2
0
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
}
Пример #3
0
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
}
Пример #4
0
func rc4(cipher *rc4P.Cipher, ciphertext []byte) []byte {
	result := make([]byte, len(ciphertext))
	cipher.XORKeyStream(result, ciphertext)
	return result
}
Пример #5
0
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
}
Пример #6
-1
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
}