【正文】
iliar with C++, the library will appear intuitive and easy to use. Others may need to view it as a learning opportunity. If you are a C++ beginner and you are under a very tight schedule, or if you are afraid of the more advanced features of C++, this library may not be for you. Having said that, you are invited to see for yourself how easy or hard it is to use by looking at some of the other answers in this category. 對熟悉c++的用戶來說 How much C++ experience do I need to use this library?How do I use the Filter class?How do I use hex encoding and decoding?How do I use a block cipher in Crypto++ ?How do I use a block cipher in Crypto++ ?How do I use a stream cipher?How do I use a hash function?How do I use a message authentication code?How do I use a random number generator?How do I use a public key cryptosystem or signature scheme?How can I use an RSA key from Crypto++ in openssl?The sample code shows how to work with a file, but my data is in a string (or vice versa).Why is ElGamal key generation so slow?I39。m trying to process multiple messages with a Filter, and MaxRetrievable() always returns 0 after the first one.(六)密碼類庫Crypto++? Library 見:\CryptoManual\\Class Hierarchy、 Compound List模板類、抽象類、類 (七)密碼類庫Crypto++? Library (1)現(xiàn)在我們就來研究一下對這個庫的用法我們在win32的操作系統(tǒng)下用vc6++來編譯Crypto++? Library 的源代碼,在對應(yīng)的目錄下會產(chǎn)生文件夾Debug,在文件夾Debug里,會有一個編譯好的靜態(tài)庫文件 我們就來研究什么用這個靜態(tài)庫文件。Hash函數(shù)的應(yīng)用 Links to cryptographic resources AdministrationHow can I contribute to this FAQ? While You Are Downloading?Take a look at the related links page. It includes links to crypto libraries for other languages, products that use Crypto++, etc. ?Consider the list of remended books for Crypto++ users. ?Examine the Crypto++ license agreement. ?Read denis bider39。s Crypto++ User Guide ?Browse the Crypto++ Reference Manual (mirrored here). ?View these Crypto++ class hierarchy charts to see how Crypto++ is organized. Note that these charts only include a small number of actual algorithms as examples. ?symmetric algorithms and hash functions ?public key algorithms Mailing ListsThere are two mailing lists for Crypto++. ?cryptoppannounce@ Crypto++ announcements ?cryptopplist@ user questions and general discussion related to Crypto++, archived at :cryptopplistrequest@?subject=subscribe with the subject subscribe to subscribe, and use unsubscribe subject to unsubscribe. When posting a question to the mailing list, please give the following information, if available: ?exact error message ?stack trace ?a minimal program with a main() function, that reproduces the problem ?versions of Crypto++, operating system (output of uname a mand if using Unix), and piler (output of gcc v if using GCC) To ContributeThe Crypto++ source code and FAQ are hosted on . ?The SourceForge CVS Repository allows you to view the latest (unreleased) Crypto++ source code and to contribute bug fixes or new features. The CVS repository contains two modules: ?src version and earlier. ?c5 version . ?The Crypto++ FaqOMatic allows you to view frequently asked questions and to contribute new questions or answers. Paid Support and ConsultingIf you are interested in paid support for Crypto++ or consulting on a Crypto++ related project, please take a look at this list of panies and individuals providing such services. This listing is a free service for the Crypto++ munity, and anyone may sign up to be listed by following the above link. Crypto++的靜態(tài)連接庫及其在Win32平臺下的使用 在win32的操作系統(tǒng)下用vc6++來編譯Crypto++? Library 的源代碼,在對應(yīng)的目錄下會產(chǎn)生文件夾Debug,在文件夾Debug里,;下面通過實例研究這個靜態(tài)庫文件的使用:在應(yīng)用lib文件時先把庫里的頭文件和lib文件復(fù)制到工程的目錄里這是最好的方法,或者把它們放到一個文件夾里修改指定的include 目錄,即在菜單Tools中選Options,在Options的對話框里選Directories 在include files和Library files 的頁面添加指向該文件夾的路徑。 、Hash函數(shù)的應(yīng)用:Hash函數(shù)的最基本的用法就是計算Hash值,一個Hash函數(shù)是一個多對一的映射,可以輸入任意長度的消息,輸出卻是一個固定長度的消息,而且,只要有一點很微小的差異的兩個消息之間的Hash值也會有很大的差異,根據(jù)兩個不同的Hash值就可以判斷對應(yīng)的兩個消息是不同的。所以Hash函數(shù)通常用于數(shù)字簽名和消息的完整性檢測等等一些安全性方面的應(yīng)用。下面舉一個計算字符串的Hash值簡單的例子。pragma ment (lib,) //加載lib文件的語句include include iostreamusing namespace CryptoPP。 //使用名字空間CryptoPP using namespace std。 //使用名字空間std void main(){ byte message[128]。 byte m[16]。 cout輸入字符串endl。 ((char*) message,128)。 MD5 md5。 (message,128)。 (m)。 for(int i=0。i16。i++)printf(%02x,m[i])。printf(\n)。 } 這個例子首先生成MD5對象(),調(diào)用方法Update()和Final(),這兩個方法是定義在基類HashTransformation里的。void Update (const byte *input, unsigned int length) 是用來處理輸入的方法,input 是byte型是將要計算Hash值的字符串,length是字符串的長度。void Final (byte *digest) 是計算當前消息的Hash值并重新開始新的消息的方法,digest是用來存放Hash值的byte型數(shù)組。HashTransformation還定義了幾個常用的方法 void CalculateDigest (byte *digest, const byte *input, unsigned int length)也是用來計算hash值的方法,可以用md5. CalculateDigest(m,message,128),(message,128)與 (m) 這兩個語句。在消息完整性檢測方面我們通常都是檢測文件的完整性,一個相當大的文件如果對其進行一個很微小的修改我們根本看不出的,但是它們的Hash值卻有很大的變化,所以我們只要比較Hash值就很容易看出該文件是否為原來的文件。計算文件的Hash值在這個密碼庫的支持下就比較簡單就用下面的一行代碼就行了FileSource f(file, true, new HashFilter(md5, new HexEncoder(new ArraySink(buffer,2 * MD5::DIGESTSIZE))))。這一行代碼總共用了4個類ArraySink、HexEncoder、HashFilter和FileSource。首先用類ArraySink復(fù)制一個2 * MD5::DIGESTSIZE 字節(jié)的buffer存儲緩沖區(qū),接著用類HexEncoder把這個緩沖區(qū)轉(zhuǎn)換為16進制。計算Hash值主要用到類HashFilter。類FileSource是把要計算Hash值的文件file進行一定的轉(zhuǎn)換放入臨時緩沖區(qū),然后調(diào)用實例化的HashFilter對其進行計算相應(yīng)Hash函數(shù)的Hash值。 對稱密碼的應(yīng)用我們說明DES的編程。DES有四種工作模式:電子密碼本模式(electronic codebook mode),密碼分組鏈接模式(cipher block chaining mode),密碼反饋模式(cipher feedback mode)以及輸出反饋模式(output feedback mode)。 應(yīng)用對稱密碼首先我們要確定用那種工作模式,即用ECB, CBC, CFB和OFB中的那種模式。Crypto++提供的工作模式對象,其本質(zhì)上是把分組密碼(block cipher)轉(zhuǎn)換成序列密碼(stream cipher)。下面就是創(chuàng)建工作模式CFB的例子:byte key[AES::DEFAULT_KEYLENGTH], iv[AES::BLOCKSIZE]。CFB_ModeAES ::Encryption cfbEncryption(key, AES::DEFAULT_KEYLENGTH, iv)。其中iv 是一個增量值,可以隨便取一個字符串。 知道什么創(chuàng)建工作模式后我們就通過具體的例子來研究對稱密碼的用法。下面我們來看高級加密標準AES在工作模式CFB下的簡單應(yīng)用。string AESEncryptString(const char *instr, co