5,137,506 members and growing! (11,940 online)
Email Password   helpLost your password?
Languages » C / C++ Language » General     Intermediate

Compression and decompression using the Crypto++ library

By Shaun Wilde

Using the Crypto++ library to compress and decompress data
VC6, C++Windows, NT4, Win2KVS6, VS, Dev

Posted: 20 Nov 2000
Updated: 16 Apr 2001
Views: 120,120
Announcements



Search    
Advanced Search
Sitemap
31 votes for this Article.
Popularity: 6.01 Rating: 4.03 out of 5
0 votes, 0.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Shaun Wilde


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 the SE and I don't get much time to program for myself or to work on my website (www.many-monkeys.com).

Spend most of my spare time with the wife+kids or working on my Marine Fish tank. Who needs a screen saver to stare at when you can have the real thing!


Occupation: Web Developer
Location: United Kingdom United Kingdom

Other popular C / C++ Language articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 49 (Total in Forum: 49) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralWell I've added header but it doesn't workmemberNoagene22:36 15 Aug '07  
GeneralRe: Well I've added header but it doesn't workmemberShaun Wilde0:28 19 Aug '07  
GeneralRe: Well I've added header but it doesn't workmemberNoagene14:38 19 Aug '07  
GeneralError code has been changed..memberNoagene19:55 19 Aug '07  
AnswerRe: Error code has been changed..memberbutuzov_Ilya23:27 6 Sep '07  
GeneralClose() is No Longer Available...memberJeffrey Walton16:21 27 May '07  
GeneralRe: Close() is No Longer Available...memberShaun Wilde11:04 28 May '07  
GeneralRe: Close() is No Longer Available...memberJeffrey Walton12:03 28 May '07  
GeneralRe: Close() is No Longer Available...memberShaun Wilde20:55 29 May '07  
GeneralRe: Close() is No Longer Available...memberJeffrey Walton12:08 28 May '07  
GeneralRe: Close() is No Longer Available...memberShaun Wilde20:56 29 May '07  
GeneralCrypto++ Integration ArticlememberJeffrey Walton19:28 8 Dec '06  
GeneralGzip work verry greatly!memberdungbkhn18:50 28 Jun '05  
GeneralGot a wrong result!memberJerryCheng23:44 11 Nov '03  
GeneralRe: Got a wrong result!memberShaun Wilde9:13 12 Nov '03  
GeneralRe: Got a wrong result!memberJerryCheng17:59 13 Nov '03  
GeneralRe: Got a wrong result!memberShaun Wilde5:43 14 Nov '03  
Generalencryption of file..help??memberxxhimanshu21:40 11 Nov '03  
GeneralRe: encryption of file..help??memberShaun Wilde9:17 12 Nov '03  
GeneralzippingsussAnonymous9:24 1 Jun '03  
GeneralRe: zippingmemberShaun Wilde11:08 1 Jun '03  
General'Close' : is not a member of 'CryptoPP::Gzip'memberÅke Johansson20:41 11 Apr '03  
GeneralRe: 'Close' : is not a member of 'CryptoPP::Gzip'memberShaun Wilde21:32 13 Apr '03  
GeneralRe: 'Close' : is not a member of 'CryptoPP::Gzip'memberÅke Johansson21:29 14 Apr '03  
GeneralRe: 'Close' : is not a member of 'CryptoPP::Gzip'memberShaun Wilde21:47 14 Apr '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-2008
Web09 | Advertise on the Code Project