Click here to Skip to main content
Click here to Skip to main content

Compression and decompression using the Crypto++ library

, 16 Apr 2001 CPOL
Rate this:
Please Sign up or sign in to vote.
Using the Crypto++ library to compress and decompress data


The Crypto++ library is a freeware library of cryptographic schemes, written by Wei Dai. However the library also contains other useful classes which are not immediately apparent when you use the library. Two of these are the Gzip and Gunzip classes which can be used to compress and decompress (zip and unzip) data.


Compressing your data could not be simpler. Say you had data pData that was of size dwLen that you wished to compress.

#include <gzip.h>

Gzip zipper(1);    // 1 is fast, 9 is slow


  byte* pCompressed = new byte[zipper.MaxRetrieveable()];

pCompressed now contains the compressed data.


You may not be surprised to know that decompression is just as easy. (dwLen is now the length of our compressed data)

Gunzip unzipper;


  byte* pData = new byte[unzipper.MaxRetrieveable()];

pData now contains the uncompressed data.


Thanks to Wei Dai for his permission to write this article in what is hoped to be a series of articles on the use of his Crypto++ library.

Latest versions

The latest versions of the Crypto++ library can be found here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shaun Wilde
Software Developer (Senior) MYOB
Australia Australia
All articles are supplied as-is, as a howto on a particular task that worked for me in the past. None of the articles are supposed to be out-of-the-box freeware controls and nor should they be treated as such. Caveat emptor.
Now living and working in Australia, trying to be involved in the local .NET and Agile communities when I can.
I spend a good chunk of my spare time building OpenCover and maintaining PartCover both of which are Code Coverage utilities for .NET.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

Questionpassword protected archive? PinmemberMatthias Blum15-Jan-09 14:23 
AnswerRe: password protected archive? PinmemberShaun Wilde16-Jan-09 1:06 
GeneralCompressing and Decompressing Data using C++ Pinmemberjassshan24-Nov-08 22:39 
GeneralGzip a set of files Pinmembersheyliger7-Jul-08 4:21 
GeneralRe: Gzip a set of files PinmemberShaun Wilde7-Jul-08 9:35 
GeneralWell I've added header but it doesn't work PinmemberNoagene15-Aug-07 22:36 
GeneralRe: Well I've added header but it doesn't work PinmemberShaun Wilde19-Aug-07 0:28 
GeneralRe: Well I've added header but it doesn't work PinmemberNoagene19-Aug-07 14:38 
GeneralError code has been changed.. PinmemberNoagene19-Aug-07 19:55 
AnswerRe: Error code has been changed.. Pinmemberbutuzov_Ilya6-Sep-07 23:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 17 Apr 2001
Article Copyright 2000 by Shaun Wilde
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid