Click here to Skip to main content
6,595,854 members and growing! (21,772 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate License: The Code Project Open License (CPOL)

Compression and decompression using the Crypto++ library

By Shaun Wilde

Using the Crypto++ library to compress and decompress data
VC6Win2K, Dev
Posted:20 Nov 2000
Updated:16 Apr 2001
Views:142,740
Bookmarked:35 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
31 votes for this article.
Popularity: 6.01 Rating: 4.03 out of 5

1

2

3
3 votes, 42.9%
4
4 votes, 57.1%
5

Introduction

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.

Compression

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


  zipper.Put(pData,dwLen);
  zipper.Close();

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

pCompressed now contains the compressed data.

Decompression

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

Gunzip unzipper;

  unzipper.Put(pCompressedData,dwLen);
  unzipper.Close();

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

pData now contains the uncompressed data.

Remarks

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.

License

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

About the Author

Shaun Wilde


Member
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.

Been involved in programming from the early '80s. First on my Spectrum, then an Amstrad. Did lots of Fortran while at University before becoming involved in Forth, Prolog, Pascal, Occam, C and eventually C++. Eventually started programming on the Windows platform using Borland’s OWL framework, during my postgraduate years. When I started work in '94, I learnt MFC followed by COM and ATL and never looked back. Now working exclusively in .NET, working on WinForms, ASP.NET and the Compact Framework using C# and VB.NET. Using every bit of the .NET framework I can such as WebServices and writing my own controls for my .NET Portal, and for the Compact Framework. Still lots I don't know, but the end of the universe hasn't happened yet - I wonder if I'll have time?

I was a permanent employee for a number of companies until Dec 2000 before going independent after the DotCom I ws involved with went DotBomb. Now supplying consulting services to various institutions in London and surrounding regions i.e. UK Smile.

Now started using BizTalk and the latest .NET framework - yeha.
Occupation: Architect
Location: United Kingdom United Kingdom

Other popular C / C++ Language articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 54 (Total in Forum: 54) (Refresh)FirstPrevNext
Questionpassword protected archive? PinmemberMatthias Blum14:23 15 Jan '09  
AnswerRe: password protected archive? PinmemberShaun Wilde1:06 16 Jan '09  
GeneralCompressing and Decompressing Data using C++ Pinmemberjassshan22:39 24 Nov '08  
GeneralGzip a set of files Pinmembersheyliger4:21 7 Jul '08  
GeneralRe: Gzip a set of files PinmemberShaun Wilde9:35 7 Jul '08  
GeneralWell I've added header but it doesn't work PinmemberNoagene22:36 15 Aug '07  
GeneralRe: Well I've added header but it doesn't work PinmemberShaun Wilde0:28 19 Aug '07  
GeneralRe: Well I've added header but it doesn't work PinmemberNoagene14:38 19 Aug '07  
GeneralError code has been changed.. PinmemberNoagene19:55 19 Aug '07  
AnswerRe: Error code has been changed.. Pinmemberbutuzov_Ilya23:27 6 Sep '07  
GeneralClose() is No Longer Available... PinmemberJeffrey Walton16:21 27 May '07  
GeneralRe: Close() is No Longer Available... PinmemberShaun Wilde11:04 28 May '07  
GeneralRe: Close() is No Longer Available... PinmemberJeffrey Walton12:03 28 May '07  
GeneralRe: Close() is No Longer Available... PinmemberShaun Wilde20:55 29 May '07  
GeneralRe: Close() is No Longer Available... PinmemberJeffrey Walton12:08 28 May '07  
GeneralRe: Close() is No Longer Available... PinmemberShaun Wilde20:56 29 May '07  
GeneralCrypto++ Integration Article PinmemberJeffrey Walton19:28 8 Dec '06  
GeneralGzip work verry greatly! Pinmemberdungbkhn18:50 28 Jun '05  
GeneralGot a wrong result! PinmemberJerryCheng23:44 11 Nov '03  
GeneralRe: Got a wrong result! PinmemberShaun Wilde9:13 12 Nov '03  
GeneralRe: Got a wrong result! PinmemberJerryCheng17:59 13 Nov '03  
GeneralRe: Got a wrong result! PinmemberShaun Wilde5:43 14 Nov '03  
Generalencryption of file..help?? Pinmemberxxhimanshu21:40 11 Nov '03  
GeneralRe: encryption of file..help?? PinmemberShaun Wilde9:17 12 Nov '03  
Generalzipping PinsussAnonymous9:24 1 Jun '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Apr 2001
Editor: Chris Maunder
Copyright 2000 by Shaun Wilde
Everything else Copyright © CodeProject, 1999-2009
Web18 | Advertise on the Code Project