Using crypto++ Topic is solved

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Using crypto++

Post by FlyingIsFun1217 » Mon Dec 04, 2006 11:29 pm

Hey,

Has anybody here used crypto++ with wxwidgets? Basically, I'm looking for an (easier) way to encrypt a wxString that will be outputted to a file...

Thanks,
FlyingIsFun1217

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Mon Dec 04, 2006 11:48 pm

When using 3rd party crypto libraries you aljmost definitely have to deal with raw memory buffers. I use Botan and to encrypt a wxString I call c_str() then when I want the string back I decrypt then call wxString::wxString(const char*)

Joel

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Re: Using crypto++

Post by emarti » Tue Dec 05, 2006 2:08 am

FlyingIsFun1217 wrote:Hey,

Has anybody here used crypto++ with wxwidgets? Basically, I'm looking for an (easier) way to encrypt a wxString that will be outputted to a file...

Thanks,
FlyingIsFun1217
I usually use this. I hope to help you.

Code: Select all

const wxChar*  Codes64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";

wxString EnCode64(wxString str)
{
int a=0,b=0,x;
const wxChar* Cstr = str.GetData();
wxString Result = wxEmptyString;
for (int i =0; i<str.Length(); i++)
    {
		wxString c = (wxString)Cstr[i];
        if(c.IsAscii())
        {
			x = Cstr[i];
			b = 256 * b + x;
			a += 8;
			while (a>=6)
				{
					a -= 6;
					x = b / (1 << a);
					b = b % (1 << a);
					Result << Codes64[x+1];
				}
		}
		else
			Result << c;
	}
    if (a>0)
		{
            x = b << (6-a);
            Result << Codes64[x+1];
        }
return Result;
}

wxString DeCode64(wxString str)
{
int a=0,b=0,x;
const wxChar* Cstr = str.GetData();
wxString Result = wxEmptyString;
static wxString StringCodes64 = wxString::Format(Codes64);
for (int i=0; i<str.Length(); i++)
	{
        x = StringCodes64.Find(Cstr[i]) - 1;
        if (x>=0)
			{
				b = b * 64 + x;
				a+= 6;
				if (a>=8)
					{
						a-= 8;
						x = b >> a;
						b = b % (1 << a);
						x %= 256;
						Result << (wxChar)x;
					}
			}
			else
				Result << (wxString)Cstr[i];
    }
return Result;
}

- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Re: Using crypto++

Post by FlyingIsFun1217 » Tue Dec 05, 2006 10:34 pm

emarti wrote:
FlyingIsFun1217 wrote:Hey,

Has anybody here used crypto++ with wxwidgets? Basically, I'm looking for an (easier) way to encrypt a wxString that will be outputted to a file...

Thanks,
FlyingIsFun1217
I usually use this. I hope to help you.

Code: Select all

const wxChar*  Codes64 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";

wxString EnCode64(wxString str)
{
int a=0,b=0,x;
const wxChar* Cstr = str.GetData();
wxString Result = wxEmptyString;
for (int i =0; i<str.Length(); i++)
    {
		wxString c = (wxString)Cstr[i];
        if(c.IsAscii())
        {
			x = Cstr[i];
			b = 256 * b + x;
			a += 8;
			while (a>=6)
				{
					a -= 6;
					x = b / (1 << a);
					b = b % (1 << a);
					Result << Codes64[x+1];
				}
		}
		else
			Result << c;
	}
    if (a>0)
		{
            x = b << (6-a);
            Result << Codes64[x+1];
        }
return Result;
}

wxString DeCode64(wxString str)
{
int a=0,b=0,x;
const wxChar* Cstr = str.GetData();
wxString Result = wxEmptyString;
static wxString StringCodes64 = wxString::Format(Codes64);
for (int i=0; i<str.Length(); i++)
	{
        x = StringCodes64.Find(Cstr[i]) - 1;
        if (x>=0)
			{
				b = b * 64 + x;
				a+= 6;
				if (a>=8)
					{
						a-= 8;
						x = b >> a;
						b = b % (1 << a);
						x %= 256;
						Result << (wxChar)x;
					}
			}
			else
				Result << (wxString)Cstr[i];
    }
return Result;
}

Do you use this to encrypt strings without using crypto++ at all? I don't see any refrence to it in the code... :)

FlyingIsFun1217

emarti
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 210
Joined: Sat May 07, 2005 8:24 pm
Location: Eskisehir, TURKEY
Contact:

Post by emarti » Wed Dec 06, 2006 10:37 am

Sorry, I do not know it that library. In fact, My solution is very easy than crypto++. I downloaded it, I am trying... I'll be write to found alternative solution. :)
- T U R K E Y ?
- I love this country!

WebSites:
http://mebt.sourceforge.net/
http://wxquran.sourceforge.net/

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Wed Dec 06, 2006 4:20 pm

emarti wrote:Sorry, I do not know it that library. In fact, My solution is very easy than crypto++. I downloaded it, I am trying... I'll be write to found alternative solution. :)
...so you don't use crypto++? If so, I'll look at the code and see how I can impliment it into my code...

FlyingIsFun1217 :)

------------------EDIT-----------------
After looking at the code, I would like to try it, but I'm not quite sure how to use it...

Would I save that code as a header file, or would I insert it it straight into my code?

Thanks!
FlyingIsFun1217

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Thu Dec 07, 2006 8:37 am

It doesn't look like encryption to me, more like base64 encoding.

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Thu Dec 07, 2006 11:55 pm

Ok, no need for help on that code...

Now I've decided to use botan. Has anybody used it before?

Thanks!
FlyingIsFun1217

lowjoel
Moderator
Moderator
Posts: 1511
Joined: Sun Jun 19, 2005 11:37 am
Location: Singapore
Contact:

Post by lowjoel » Fri Dec 08, 2006 4:15 am

I use it! read the earlier post

FlyingIsFun1217
Super wx Problem Solver
Super wx Problem Solver
Posts: 497
Joined: Mon Nov 06, 2006 9:58 pm

Post by FlyingIsFun1217 » Fri Dec 08, 2006 9:12 pm

Whoops! Thanks for the hint...

I'll see if I can't get it to work by myself before I plead for the mercy of you guys ;)

FlyingIsFun1217

Post Reply