Hi all,
i'm new to Crypto++ and need some help please.
I want to do a custom filter that basically takes a passphrase,
generate salt for key derivation (using PKCS5) and encrypts data
coming from the chain to the outer chain.
The idea is to use the custom filter like:
std::string cyphertext;
CryptoPP::StringSource( PlainText, true,
new CryptoPP::MyPassphrasedEncrypt( (byte*)"David",5,
new CryptoPP::StringSink( cyphertext )
)// MyPassphrasedEncrypt
);
As for now my custom filter class is like this:
class MyPassphrasedEncrypt : public Filter
{
private:
typedef PKCS5_PBKDF2_HMAC<SHA1> PBKDF;
ECB_Mode< AES >::Encryption m_cipher;
SecByteBlock m_passphrase;
//SecByteBlock m_derivedKey;
SecByteBlock m_salt;
const int m_purpose;
string m_string;
const size_t KEYSIZE;
CRYPTOPP_CONSTANT(KEY_ITERATIONS = 10 );
RandomPool m_rng;
public:
MyPassphrasedEncrypt(const byte* passphrase,
size_t passphraseLength,
BufferedTransformation
*attachment = NULL):
Filter(attachment)
{ std::cout << "MyPassphrasedEncrypt constructor" << endl;
}
size_t Put2(const byte * inString,
size_t length, int messageEnd, bool blocking )
{
std::cout << "MyPassphrasedEncrypt::Put2()" <<
std::endl;
// Nothing to process for us. But we will pass it on to
the lower
// filter just in case...
if( 0 == length )
{
return AttachedTransformation()->Put2(
inString, length, messageEnd, blocking
);
}
const unsigned int SEEDSIZE = 16;
byte pcbSeed[ SEEDSIZE ];
// Scratch Area
const unsigned int BLOCKSIZE = 8;
byte pcbScratch[ BLOCKSIZE ];
// Random Block Initalization
m_rng.Put( pcbSeed, SEEDSIZE );
memset(pcbScratch,0,BLOCKSIZE);
m_rng.GenerateBlock( pcbScratch, BLOCKSIZE );
SecByteBlock m_derivedKey(16);
SecByteBlock saltFromRamdomPool(pcbScratch,BLOCKSIZE);
// Derive the key
PBKDF().DeriveKey( m_derivedKey, m_derivedKey.size(),
m_purpose,
(byte *)m_passphrase.data(),
m_passphrase.size(),
(byte *)saltFromRamdomPool.data(),
saltFromRamdomPool.size(),
KEY_ITERATIONS);
std::cout << "m_derivedKey: " << m_derivedKey << endl;
m_cipher.SetKey(m_derivedKey, m_derivedKey.size());
Attach(new StreamTransformationFilter(m_cipher));
size_t putSize = AttachedTransformation()->Put2(
inString, length, messageEnd, blocking );
cout << "putSize: " << putSize;
return putSize;
}
bool IsolatedFlush(bool hardFlush, bool blocking) { return
false; }
};
The code inside Put2 is the code i tested within a function and it
works but i'd really like to use it as a custom filter.
Even though i set new trasnformation filter to my cypher
transformation i still get the PlainText and not the encrypted one.
Can anyone help me please.
Thanks in advance.
David
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.