Click here to Skip to main content
15,891,529 members
Articles / Programming Languages / C++

Compiling and Integrating Crypto++ into the Microsoft Visual C++ Environment

,
Rate me:
Please Sign up or sign in to vote.
4.81/5 (45 votes)
5 May 2011CPOL16 min read 517K   990   183  
Avoid common pitfalls when using Crypto++ and VC++.
// sample.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

// Runtime Library Includes
#include <string>
#include <iostream>
#include<iomanip>

// Crypto++ Include
#include "osrng.h" // PRNG

int main(int argc, char* argv[])
{   
    // Scratch Area
    const unsigned int BLOCKSIZE = 16 * 8;
    byte pcbScratch[ BLOCKSIZE ];

    // Random Block
    CryptoPP::AutoSeededRandomPool rng;
    rng.GenerateBlock( pcbScratch, BLOCKSIZE );

    // Output
    std::cout << "The generated random block is:" << std::endl;
    for( unsigned int i = 0; i < BLOCKSIZE; i++ )
    {
        std::cout << "0x" << std::setbase(16) << std::setw(2) << std::setfill('0');
        std::cout << static_cast<unsigned int>( pcbScratch[ i ] ) << " ";
    }
    std::cout << std::endl;

    return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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


Written By
Systems / Hardware Administrator
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Written By
Architect Currently Retrenched - Looking at Consulting
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions