|
Probably the problem is, that you will have to support an initialisation when you create an instance, so that the (right) constructor will be called:
CBlowFish BlowFish( (unsigned char*)"Password", 8 );
|
|
|
|
|
I encrypted text using password "aaaa" and decrypted it with password "aaa".
char buf[] = "Test it!";
CBlowFish bf((unsigned char*)"aaaa", 4);
bf.Encrypt((unsigned char*)buf, strlen(buf));
CBlowFish bf2((unsigned char*)"aaa", 3);
bf2.Decrypt((unsigned char*)buf, strlen(buf));
How is that possible? Is it feature of blowfish? Is there any possibility to resolve this?
|
|
|
|
|
Your password key is not a multiple of 8. Might this cause a problem?
|
|
|
|
|
After inspecting the code, I saw that when using the inputted key to modify the algorithm's internal key structure...it needs to do it in 4-byte increments. When your key doesn't round perfectly what it ends up doing is wrapping around back to the front to fill in the last few bytes. So, 'aaaa' would work the same as 'aaa', but not the same as 'aaaaa'.
|
|
|
|
|
Hi!
How can I decode a file which is encrypted with Little-Endian-Blowfish?
THX
Mr. S
|
|
|
|
|
i got the following error when i try to compile the program
d:\blowfish\test\blowfish.cpp(607) : fatal error C1010: unexpected end of file while looking for precompiled header directive
Generating Code...
Error executing cl.exe.
Any suggestions?
tnx...
quistiun
|
|
|
|
|
Go to menu Project|Settings. Expand your project and look for blowfish.cpp in your project and click it. On the right pane, click C/C++ tab. On the Category Select 'Precompiled Headers'. Click 'Not using a precompiled header' then click Ok.
Hope this will help you.
"We don't see things how they are. We see things as we are." -Talmud
|
|
|
|
|
tnx, it works.
One more thing, what does it means precompiled header?
Sorry, im new in c++ programming...
quistiun
|
|
|
|
|
Very nice and helpfull! You 've got my 5
-- modified at 2:52 Tuesday 14th March, 2006
|
|
|
|
|
Hello.
We would like to use your sources in commercial projects.
Can we use them free? Without any issures?
And is it possible to receive confirming for free using in our software?
thanks,
Andrei Levin, mailto:andrei.levin@muehlbauer.de
------------------------------------------------
Muehlbauer AG, Germany; Software Development.
Phone ++49 (9461) 952-574
http://www.muehlbauer.de
------------------------------------------------
|
|
|
|
|
Hi,
maybe, i am , because i'm very helpless.
I have used the this BlowFish implementation in a C++-Programm.
My Ppoblem is:
When i don't know long is the original decrypted String,
which value have the third parameter of "Decrypt(const unsigned char* in, unsigned char* out, size_t n, int iMode=ECB);"?
... i have no crystal ball an i'm not an visionary
Every help is most welcome!
Thank you in advance!
cu
Claus
|
|
|
|
|
you would probably be able to count the elements in the character array returned.
i once had a problem with this, so i created a function for this:
int Count(char* array)
{
int a = 1;
for (;;a++)
{
if (&array[a] == 0) break;
}
return a;
}
input the buffer, and the integer returned should be the size of the string. if there are any problems, just reply.
|
|
|
|
|
hi there,
currently i am working on a server/client which uses blowfish to encrypt/decrypt the message protocal.
the problem i am facing is i was trying to implement code
but the result doesn't looks right.
encrypted
0xEA,0xC4,0x60,0x77,
0x14,0x6A,0xBC,0x23,
0x3B,0x36,0xFC,0x34,
0xA0,0xDD,0x82,0xAF,
0xD6,0x9E,0xAB,0x38,
0x05,0xB1,0xE6,0x98,
0x0D,0x2D,0x41,0x44,
0x78,0x22,0x29,0xB6,
0x76,0x62,0x4A,0x79,
0xFE,0x01,0xED,0x06,
0x51,0xE7,0x19,0xE1,
0x35,0x1E,0xAA,0x19
should be decrypted to something like this
0x00,0x74,0x6f,0x72,
0x75,0x6e,0x65,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x63,
0x68,0x65,0x6e,0x77,
0x65,0x69,0x00,0x00,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x78,0x16,0x64,0x6e,
0x00,0x00,0x00,0x00
with the encrypt key: [;'.]94-31==-%&@!^+]\0
I have no idea why its wrong.
my test code is following
<br />
<br />
#include<br />
#include<br />
#include "Blowfish.h"<br />
<br />
using namespace std;<br />
<br />
void main()<br />
{<br />
try<br />
{<br />
ofstream out("out.txt", ios::trunc);<br />
char ENCRYPTKEY[] = "[;'.]94-31==-%&@!^+]";<br />
unsigned char decrypted[] = {<br />
0x00,0x74,0x6f,0x72,0x75,0x6e,0x65,0x00,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x63,<br />
0x68,0x65,0x6e,0x77,0x65,0x69,0x00,0x00,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,<br />
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,<br />
0x78,0x16,0x64,0x6e,0x00,0x00,0x00,0x00<br />
};<br />
<br />
unsigned char encrypted[] = {<br />
0xEA,0xC4,0x60,0x77,0x14,0x6A,0xBC,0x23,<br />
0x3B,0x36,0xFC,0x34,0xA0,0xDD,0x82,0xAF,<br />
0xD6,0x9E,0xAB,0x38,0x05,0xB1,0xE6,0x98,<br />
0x0D,0x2D,0x41,0x44,0x78,0x22,0x29,0xB6,<br />
0x76,0x62,0x4A,0x79,0xFE,0x01,0xED,0x06,<br />
0x51,0xE7,0x19,0xE1,0x35,0x1E,0xAA,0x19<br />
};<br />
unsigned char szDataOut[48];<br />
CBlowFish oBlowFish((unsigned char*)ENCRYPTKEY, sizeof(ENCRYPTKEY));<br />
oBlowFish.Encrypt(decrypted, (unsigned char*)szDataOut, sizeof(decrypted), CBlowFish::ECB);<br />
out <<szDataOut<<endl;<br />
<br />
memset(szDataOut,0,sizeof(szDataOut));<br />
oBlowFish.Decrypt(encrypted, (unsigned char*)szDataOut, sizeof(encrypted), CBlowFish::ECB);<br />
out <<szDataOut<<endl;<br />
}<br />
catch(exception& roException)<br />
{<br />
cout << "Exception: " << roException.what() << endl;<br />
}<br />
}<br />
-- modified at 22:09 Friday 2nd September, 2005
|
|
|
|
|
Hello,
I have not tested your code but looking through the documentation stated:
The function ResetChain() is used to reset the chaining block before starting a new encryption or decryption operation.
Give it a try.
CBlowFish oBlowFish((unsigned char*)ENCRYPTKEY, sizeof(ENCRYPTKEY));
//Test ECB
oBlowFish.Encrypt(decrypted, (unsigned char*)szDataOut, sizeof(decrypted), CBlowFish::ECB);
out <<szdataout<<endl;
memset(szdataout,0,sizeof(szdataout));
<b>oBlowFish.ResetChain(); //add this
oBlowFish.Decrypt(encrypted, (unsigned char*)szDataOut, sizeof(encrypted), CBlowFish::ECB);
out <
|
|
|
|
|
I have a program that has text in it. When I go to save the text to a file I want to encrypt it. Then when I open it of course if I supply the right key it should decrypt it correctly. The problem I think I am having is that when I encrypt it I'm using CString GetLength() method and then making sure that it is using up the whole 8 bytes on the end (using ECB mode). But how do u know what to pass when decrypting the same text when opening the file. The file doesn't know what to use? Thanks in advance.
Jack
|
|
|
|
|
Is there a simple std::string version like
string encrypt(string input, string key);
string decrypt(string input, string key);
Or encrypt/decrypt for abritary length byte data
I think it would be a lot easier to use. Thanks.
|
|
|
|
|
internal you would to turn the string in a char array too
|
|
|
|
|
>the block of data size should be a multiple of the block size which is always 8 bytes
Hi all,
how should I handle the situation with arbitrary buffers? I can extend the input buffer by encription, but how ca I decrease the size of the output buffer by decription, if I don't know the initail size anymore?
|
|
|
|
|
|
I added the following code to the header file:
inline unsigned long CalcCryptogramSize(unsigned long dwLen, bool bPadding = true, bool bCBC = false)
{
return ((((dwLen)/8) + (((dwLen) % 8 > 0) ? 1 : ((bPadding) ? 1 : 0)) + ((bCBC) ? 1 : 0)) * 8);
}
Edit: Sorry the reply is a month late. I hope it is of help to somebody.
|
|
|
|
|
We found the Blowfish C++ source code developed by Jim Conger on http://www.schneier.com/blowfish-download.html (C++ by Jim Conger)
web site.
We are planning to use Blowfish C++ source code in one of my applications.
According to website, it is mentioned that source code is "Unpatented and royalty-free".
We have following queries in using the Blowfish source code:
1. Do we need to get any licence in using the source code?
2. If licence is not required, can we get a certificate to use it
for "unlimited commercial purpose" (Process to get the certificate)?
Please provide information for the above queries.
|
|
|
|
|
I will try to answer you.
1. no you don't have to get any licence as the author says.
2. no. I think you can't get a such a certificate.
|
|
|
|
|
Hi, this is probably something I'm doing wrong, but if I try to encrypt and decrypt with different instances of the CBlowFish component, the decryption doesn't produce the original text.
I'm using Borland C++Builde 6.0 professional.
For example, with the following code snippet (based on the original author's code), I do get symmetric encryption/decryption.
CBlowFish* bf;
bf = new CBlowFish((unsigned char*)"1234567890123456", 16);
char szDataIn1[49] = "ababababccccccccababababccccccccababababcccccccc";
char szDataIn[49];
char szDataOut[49];
memset(szDataIn, 0, 49);
memset(szDataOut, 0, 49);
strcpy(szDataIn, szDataIn1);
memset(szDataOut, 0, 49);
bf->Encrypt((unsigned char*)szDataIn,
(unsigned char*)szDataOut, 48, CBlowFish::ECB);
memset(szDataIn, 0, 49);
bf->Decrypt((unsigned char*)szDataOut,
(unsigned char*)szDataIn, 48, CBlowFish::ECB);
delete bf;
BUT, if I do the following, I don't get symmetric encryption/decryption
CBlowFish* bf;
bf = new CBlowFish((unsigned char*)"1234567890123456", 16);
char szDataIn1[49] = "ababababccccccccababababccccccccababababcccccccc";
char szDataIn[49];
char szDataOut[49];
memset(szDataIn, 0, 49);
memset(szDataOut, 0, 49);
strcpy(szDataIn, szDataIn1);
memset(szDataOut, 0, 49);
bf->Encrypt((unsigned char*)szDataIn,
(unsigned char*)szDataOut, 48, CBlowFish::ECB);
CBlowFish* bf2;
bf2 = new CBlowFish((unsigned char*)"1234567890123456", 16);
memset(szDataIn, 0, 49);
bf2->Decrypt((unsigned char*)szDataOut,
(unsigned char*)szDataIn, 48, CBlowFish::ECB);
delete bf;
delete bf2;
Should I expect this to work? If not, does this mean that I can't use Blowfish to encrypt on one platform and decrypt on another?
|
|
|
|
|
Hello, I have the simmilar problem. I have to decrypt a text encrypted with
mcrypt php. The first 8 bytes are not decrypted OK. The rest is OK. Did anyone encounter the same problem?
What can I do to repare this bug? And from who this bug come? From mcrypt php or this blowhfish impl?
If you want I can send you the key and encrypted text from mcrypt and decrypted text from CBlowFish.
Thanks.
|
|
|
|
|
(1) Blowfish.cpp failed compile. Around line 318, the compiler complains the variable iVal is not used. Either this variable was defined, but the code author forgot to use the variable. Or maybe we don't even need this variable at all.
(2) In the code they throw exceptions like "throw exception("Incorrect key length")". But there is no class exception defined, and std::exception is abstract and has no constructor taking one argument. So I included <stdexcept> instead, put a using std::runtime_error after the include directives, and replace "throw exception" with "throw runtime_error".
(3) The compiler complains the memcpy is not defined, so after the include directives I put a "using std::memcpy".
(4) In the constructor, it is a good idea to declare ucKey as "const unsigned char * ucKey", that is with the const.
(5) We can implement the Encrypt and Decrypt that work in place in terms of the ones that work on an external buffer. Just call Encypt(in, in, n, iMode) to encrypt in place. However, I wrote general template functions
template <class InputIter, class OutputIter> void Encrypt(InputIter begin, Iter end, int iMode=ECB);
template <class InputIter, class OutputIter> void Decrypt(InputIter begin, Iter end, int iMode=ECB);
which are useful if we want to encrypt/decrypt std::string (as we can't assume that the implementation stores strings as an array of chars though all I know of do), and other containers.
(6) We should implement easy checking. In the test driver, we could write to an ostringstream instead of an ofstream (that is, declare out as of type ostringstream). Then get the contents of the string by calling out.str(). Place the expect results into a char[] string such as
const char * expect =
"0000000000000000 0000000000000000 4EF997456198DD78\n"
"FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866FD5B85ECB8A\n"
...
;
And finally
const std::string actual = out.str();
bool pass = actual == expect;
cout << "pass = " << pass << "\n\n";
ofstream outfile("out.txt", ios::trunc);
outfile << "pass = " << pass << "\n\n";
outfile << actual << "\n";
outfile << expect << "\n";
(7) In the test driver, in the line
if(byte[i] >= 0 && byte[i] <= 9)
the byte[i] >= 0 is always true because byte[i] has type unsigned char. So one can just use
if(byte[i] <= 9)
|
|
|
|
|