crypto++使用DES加密(ECB pkcs7padding )
生活随笔
收集整理的這篇文章主要介紹了
crypto++使用DES加密(ECB pkcs7padding )
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
zeropadding
ZeroPadding,數(shù)據(jù)長度不對(duì)齊時(shí)使用0填充,否則不填充。使用0填充有個(gè)缺點(diǎn),當(dāng)元數(shù)據(jù)尾部也存在0時(shí),在unpadding時(shí)可能會(huì)存在問題。
pkcs7padding
假設(shè)每個(gè)區(qū)塊大小為blockSize
<1>已對(duì)齊,填充一個(gè)長度為blockSize且每個(gè)字節(jié)均為blockSize的數(shù)據(jù)。
<2>未對(duì)齊,需要補(bǔ)充的字節(jié)個(gè)數(shù)為n,則填充一個(gè)長度為n且每個(gè)字節(jié)均為n的數(shù)據(jù)。
pkcs5padding
PKCS7Padding的子集,只是塊大小固定為8字節(jié)。
ECB 模式
//加密 string DES_encrypt(const char *key, string &content){string cipher;try{ECB_Mode<DES>::Encryption e;e.SetKey((const byte*)key, DES::KEYLENGTH);StringSource(content, true, new StreamTransformationFilter(e,new StringSink(cipher)));}catch (const Exception &e){cout << e.what() << endl;}return cipher; } //解密 string DES_decrypt(const char *key, string &cipher){string plain;try{ECB_Mode<DES>::Decryption e;e.SetKey((const byte*)key, DES::KEYLENGTH);StringSource(content, true, new StreamTransformationFilter(e,new StringSink(plain)));}catch (const Exception &e){cout << e.what() << endl;}return plain; }總結(jié)
以上是生活随笔為你收集整理的crypto++使用DES加密(ECB pkcs7padding )的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: version.dll劫持注入模版
- 下一篇: ReadDirectoryChanges