Click here to Skip to main content
Licence CPOL
First Posted 20 Nov 2000
Views 172,762
Downloads 1,490
Bookmarked 44 times

Compression and decompression using the Crypto++ library

By Shaun Wilde | 16 Apr 2001
Using the Crypto++ library to compress and decompress data

1

2

3
3 votes, 42.9%
4
4 votes, 57.1%
5
4.03/5 - 31 votes
μ 4.03, σa 1.07 [?]

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

Architect

United Kingdom United Kingdom

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 living and working in Australia, trying to be involved in the local .NET and Agile communities. Also maintaining an open source code coverage tool called PartCover whilst thinking of developing a new one.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
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  
Halo,do someone have Compressing and Decompressing Data using C++ source code.IF u guys n girls have,can u all sent me the source code.my email at whocares1717@hotmail.com.thx
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  
Questionencryption of file..help?? Pinmemberxxhimanshu21:40 11 Nov '03  
AnswerRe: encryption of file..help?? PinmemberShaun Wilde9:17 12 Nov '03  
Generalzipping PinsussAnonymous9:24 1 Jun '03  

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.

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