Esempio n. 1
0
func fastTestConstruction() *chow.Construction {
	if !isCached {
		constr1, _ := testConstruction()
		serialized := constr1.Serialize()
		cached, _ = chow.Parse(serialized)

		isCached = true
	}

	return &cached
}
Esempio n. 2
0
func main() {
	flag.Parse()

	// Load in key data and initialize the block cipher.
	keyData, err := ioutil.ReadFile(*key)
	if err != nil {
		panic(err)
	}

	block, _ := chow.Parse(keyData)

	// Put block cipher in CBC mode.
	iv := make([]byte, 16)
	rand.Read(iv)

	fmt.Printf("IV: %x\n", iv)

	mode := cipher.NewCBCEncrypter(block, iv)

	// Load in file to encrypt.
	data, err := ioutil.ReadFile(*in)
	if err != nil {
		panic(err)
	}

	// Create and append the padding for our file.
	padding := make([]byte, 16-len(data)%16)

	for i, _ := range padding {
		padding[i] = byte(len(padding))
	}

	data = append(data, padding...)

	// Encrypt file.
	mode.CryptBlocks(data, data)

	// Write encrypted file to disk.
	ioutil.WriteFile(*out, data, os.ModePerm)

	fmt.Println("Done!")
}