Пример #1
0
func create_readers(ciphers *[]block.Cipher) *[]io.Reader {
	reader := &NullReaderWriter{}

	// ECB, CBC, CTR, OFB ...?
	readers := make([]io.Reader, len(*ciphers)*4)

	for i, cipher := range *ciphers {

		readers[i] = block.NewECBDecrypter(cipher, io.LimitReader(reader, 1024*1024*16))
		readers[i+len(*ciphers)] = block.NewCBCDecrypter(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))
		readers[i+2*len(*ciphers)] = block.NewCTRReader(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))
		readers[i+3*len(*ciphers)] = block.NewOFBReader(cipher, gen_iv(cipher), io.LimitReader(reader, 1024*1024*16))

	}
	return &readers
}
Пример #2
0
// Decrypt using MySQL AES Decrypt
func AESDecrypt(in, key []byte) []byte {
	cipher, err := aes.NewCipher(aesKey(key))
	if err != nil {
		return nil
	}

	pBuf := bytes.NewBuffer(make([]byte, 0, len(in)))

	cRdr := block.NewECBDecrypter(cipher, bytes.NewBuffer(in))
	_, err = pBuf.ReadFrom(cRdr)
	if err != nil {
		return nil
	}

	pText := pBuf.Bytes()
	if len(pText) < 1 {
		return nil
	}
	lenpt := len(pText) - int(pText[len(pText)-1])
	if lenpt < 0 {
		return nil
	}
	return pText[:lenpt]
}