Hi,
I have written encrypt/decrypt functions that use blowfish and the issue is
that they works fine if the input string length is divisible by 8. I have found
in docs that blowfish uses 8 byte blocks. So I must do padding. Do I have to do
it manually or is there any function that does it for me ?
encrypt:
void encrypt_message(const char *buffin, size_t buffinSize, char
**buffout, const
char *key)
{
BIO *mem = BIO_new(BIO_s_mem());
BIO *b64=BIO_new(BIO_f_base64());
BIO *cipher=BIO_new(BIO_f_cipher());
BIO_set_cipher(cipher, EVP_bf_ecb(), (unsigned char*)key, NULL,1);
BIO_push(cipher,b64);
BIO_push(b64, mem);
int len=0;
char buff[1024];
for (int tot=0; tot<buffinSize; tot+=len) {
if ((len=BIO_write(cipher,buffin,buffinSize))<=0) {
if (BIO_should_retry(cipher)) {
len=0; continue;
}
break;
}
}
char *encryptedbuff=NULL;
BIO_flush(cipher);
int encryptedlength = BIO_get_mem_data(mem, &encryptedbuff);
cout<<encryptedlength<<endl;
*buffout=new char[encryptedlength];
strncpy(*buffout,encryptedbuff,encryptedlength);
BIO_free_all(cipher);
BIO_free(b64);
BIO_free(mem);
}
Decrypt works similarly: I write encrypted string to "mem" and do reading from
cipher.
Thanks in advance
---------------------------------
Czy już jesteś w Yahoo!?
Masz dosyć spamu? Poczta Yahoo! dysponuje najlepszą ochroną przed spamem
http://pl.mail.yahoo.com