Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Jun 27, 2017 5:21 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Plugin to encrupt textfield value
PostPosted: Wed Jan 04, 2012 4:38 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
hi,
I am new to realbasic. I want to encrypt the text of a "textfield" before store it into database. Is there any plugin available to achieve this? Is so, what is that plugin? or can it be achieved in another way ?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Last edited by amitavak on Wed Jan 04, 2012 7:49 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Plug to encrupt textfield value
PostPosted: Wed Jan 04, 2012 4:54 am 
Offline
User avatar

Joined: Tue Jan 04, 2011 3:02 am
Posts: 1236
Location: Jönköping, Sweden
It depends on what encryption you want to use.
Personally I use AES-256 for my databases. I don't know if there's a plugin for that so I use OpenSSL. It also encodes the encrypted string into Hex.

I've created a function that you can use if you want it:
      Function aes_256_cbc(enc_mode as String, str_in as String, secr_key as String) As String
       Dim sh as New Shell
       Dim s as String
      
       if enc_mode = "encrypt" then
       sh.Execute("echo -n " + chr(34) + str_in + chr(34) + " | openssl enc -aes-256-cbc -a -pass pass:" + secr_key)
       s = EncodeHex(sh.Result)
       sh.close
       if Left(s, 5) = "error" then
       //error
       end if
       Return DefineEncoding(s, Encodings.UTF8)
       end if
      
       if enc_mode = "decrypt" then
       sh.Execute("echo " + chr(34) + DecodeHex(str_in) + chr(34) + " | openssl enc -aes-256-cbc -a -d -pass pass:" + secr_key)
       s = sh.Result
       sh.close
       if Left(s, 5) = "error" then
       //error
       end if
       Return DefineEncoding(s, Encodings.UTF8)
       end if
      End Function


Use it like this:
s = aes_256_cbc("encrypt", "string_to_encrypt", "secret_key_to_use")


PS. There's room for better error checking that you might add ;)

_________________
Image http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
Xojo Pro 2013r1


Top
 Profile  
Reply with quote  
 Post subject: Re: Plug to encrupt textfield value
PostPosted: Wed Jan 04, 2012 5:18 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
thanks for ur reply !!

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plug to encrupt textfield value
PostPosted: Wed Jan 04, 2012 5:19 am 
Offline
User avatar

Joined: Tue Jan 04, 2011 3:02 am
Posts: 1236
Location: Jönköping, Sweden
amitavak wrote:
thanks for ur reply !!


You can change it to use any of the encryptions that OpenSSL supports, thats a good thing :)
Let me know if you need help using it :)

_________________
Image http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
Xojo Pro 2013r1


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Wed Jan 04, 2012 8:55 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
I used "AspEncrypt" to encrypt file as well as record in Asp.net. I am new to this platform. Now want to use that "AspEncrypt" dll file in realbasic. How can I do it? Is there any plugin avilable for the same purpose?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Wed Jan 04, 2012 9:00 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
The above solution may not work on Windows, unless there is an OpenSSL command line utility included as part of the OS install.

OpenSSL IS part of OSX.... so that code will work there.

Elsewhere on this forum (and I can post the code if you want)..... is an RealStudio only code version of the RC4 algorithm .... perhaps not as secure as AES.... but it might serve your purpose


Also if you have the Pro/Enterprise version of RS.... you have the ability to encrypt the entire database as well

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Wed Jan 04, 2012 10:10 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
thank you Daves !!
That's right. The code isn't working in windows. So can you post that code you are talking about.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Wed Jan 04, 2012 10:14 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
Private Function RC4(strData as string, strKey as String) As string
#If Not DebugBuild
#pragma DisableBackgroundTasks
#pragma DisableBoundsChecking
#pragma DisableAutoWaitCursor
#pragma StackOverflowchecking False
#pragma NilObjectChecking False
#EndIf
Dim MM As MemoryBlock = strData
Dim MM2 As New MemoryBlock(LenB(strData))
Dim memAsciiArray(255) As Integer
Dim memKeyArray(255) As Integer
Dim memJump As Integer
Dim memTemp As Integer
Dim memY As Integer
Dim intKeyLength As Integer
Dim intIndex As Integer
Dim intT As Integer
Dim intX As Integer

intKeyLength = Len(strKey)

For intIndex = 0 To 255
memKeyArray(intIndex) = Asc(Mid(strKey, ((intIndex) Mod (intKeyLength)) + 1, 1))
Next

For intIndex = 0 To 255
memAsciiArray(intIndex) = intIndex
Next

For intIndex = 0 To 255
memJump = (memJump + memAsciiArray(intIndex) + memKeyArray(intIndex)) Mod 256
memTemp = memAsciiArray(intIndex)
memAsciiArray(intIndex) = memAsciiArray(memJump)
memAsciiArray(memJump) = memTemp
Next

intIndex = 0
memJump = 0

For intX = 1 To MM2.Size
intIndex = (intIndex + 1) Mod 256
memJump = (memJump + memAsciiArray(intIndex)) Mod 256
intT = (memAsciiArray(intIndex) + memAsciiArray(memJump)) Mod 256
memTemp = memAsciiArray(intIndex)
memAsciiArray(intIndex) = memAsciiArray(memJump)
memAsciiArray(memJump) = memTemp
memY = memAsciiArray(intT)
mm2.Byte(intX - 1) = bitwise.bitxor(Val("&h" + Hex(MM.Byte(IntX - 1))), bitwise.bitxor(memTemp,memY))
Next

Return MM2
End Function



usage (RC4 is a bidirectional cypher)
encrypted_text=encodebase64(rc4(clear_text,mykey))

clear_text=s=rc4(DecodeBase64(encrypted_text,mykey))

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Thu Jan 05, 2012 10:06 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
hi, Daves!!
Using your code I can successfully encrypt a string. As you describe...
encrypted_text=encodebase64(rc4(clear_text,mykey))


but how do I decrypt that string. Using the following code it throws error as rc4 take two parameter.

clear_text=s=rc4(DecodeBase64(encrypted_text,mykey))


can you please help me?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Thu Jan 05, 2012 10:13 am 
Offline

Joined: Fri Jan 23, 2009 9:18 am
Posts: 104
Location: Summerfield, Florida
amitavak wrote:
clear_text=s=rc4(DecodeBase64(encrypted_text,mykey))


A slip of the )

Try
clear_text=s=rc4(DecodeBase64(encrypted_text),mykey)

Jim


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Thu Jan 05, 2012 10:22 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
thanks a lot.
It works !!

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Fri Jan 06, 2012 12:46 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
One more question can this code encrypt the file also? If yes then how?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Fri Jan 06, 2012 1:20 am 
Offline
User avatar

Joined: Sun Aug 05, 2007 10:46 am
Posts: 4931
Location: San Diego, CA
You'd have to do it in sections I believe....

I am not sure, but I think this code as-is is limited to 255 character strings......

_________________
Dave Sisemore
iMac I7[2012], OSX Mountain Lion 10.8.3 RB2012r2.1
Note : I am not interested in any solutions that involve custom Plug-ins of any kind


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Fri Jan 06, 2012 2:14 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
hi dave,
can you please provide me a function that can encrypt a file as well?

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
 Post subject: Re: Plugin to encrupt textfield value
PostPosted: Fri Jan 06, 2012 2:43 am 
Offline
User avatar

Joined: Mon Jan 02, 2012 1:51 am
Posts: 382
Location: India
Actually I have a image file and a XML file in a folder. I want to encrypt these files and store it some folder.

_________________
Amitava Karan
Real Studio 2012 Release 1
Windows 7 (32 bit)
Mac OS X Version 10.7


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group