Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do you use _crypt class library
Message
From
27/02/2003 19:19:43
 
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00758880
Message ID:
00759184
Views:
23
>I have a form that has a memo field and I need the data in that memo field to be encrypted as it has passwords and other sensitive information in it. How can I use the _crypt class library to ensure that the data is encrypted in the database file?

A simple example:
*============================================
* Program: DOCRYPTO.PRG
* cCipher = x.EncryptStream("This is easy", ;
*  "look Ma, no hands!")
*============================================
x = CREATEOBJECT("docrypto")
? x.EncryptStream("This is easy", "look Ma, no hands!")
return




DEFINE CLASS docrypto AS Session && OLEPUBLIC

PROTECTED oCrypto
oCrypto = ""
MinimumPasswordLength = 5


*********************************************
PROCEDURE Init

this.oCrypto = NEWOBJECT("_cryptapi", Home(1) + "\Ffc\_crypt.vcx")

IF VARTYPE(this.oCrypto) != "O"
  RETURN .f.
ENDIF

ENDPROC



*********************************************
PROCEDURE EncryptStream(tcString as Character, tcPassword as Character) as Character

IF PCOUNT() < 2
RETURN "Usage: EncryptStream(String, Passphrase)"
ENDIF

LOCAL lcEncryptedStream

IF EMPTY(tcString)
  RETURN "Nothing to do!"
ENDIF

IF LEN(tcPassWord) < nMinimumPasswordLength
  RETURN "Passphrase must >= " + TRANSFORM(nMinimumPasswordLength) + " chars!"
ENDIF

IF This.oCrypto.EncryptSessionStreamString(tcString, tcPassWord, @lcEncryptedStream)
  RETURN lcEncryptedStream
ELSE
  RETURN .F.
ENDIF
ENDPROC




*********************************************
PROCEDURE DecryptStream(tcEncryptedString as Character, tcPassWord as Character) as Character
IF PCOUNT() < 2
  RETURN "Usage: DecryptStream(EncryptedString, Passphrase)"
ENDIF

LOCAL lcDecryptedString
IF EMPTY(tcEncryptedString)
  RETURN "Nothing to do!"
ENDIF

IF LEN(tcPassWord) < nMinimumPasswordLength
  RETURN "Passphrase must >= " + TRANSFORM(nMinimumPasswordLength) + " chars!"
ENDIF

IF This.oCrypto.DecryptSessionStreamString(tcEncryptedString, tcPassWord, @lcDecryptedString)
    RETURN lcDecryptedString
ELSE
    RETURN .F.
ENDIF
ENDPROC



*********************************************
PROCEDURE Destroy
  this.oCrypto = .null.
ENDPROC



*********************************************
PROCEDURE Error(nError, cMethod, nLine)
  RETURN MESSAGE() + " - (" + TRANSFORM(ERROR()) + ")"
ENDPROC

ENDDEFINE
HTH


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Reply
Map
View

Click here to load this message in the networking platform