Author | Topic: tdEnc()/tdDec() | |
---|---|---|
Donald Keating | tdEnc()/tdDec() on Sat, 09 Feb 2013 15:44:57 -0500 Hi Y'all, This is snippet of my code for my testing. usr->(dbrlock()) USR->PASS:= tdenc("ipps") usr->(dbrunlock()) cPASS:= tddec(USR->PASS) Seems to me cPASS should = "ipps" but, it is "ipps©®Âª¬³ú´¯µ¶Ð²û»è". What am I doing wrong? Thanks. >don< | |
Klaus Overhage | Re: tdEnc()/tdDec() on Sun, 10 Feb 2013 10:47:27 +0100 Don, maybe with Rtrim ? Am 09.02.2013 21:44, schrieb Donald Keating: > Hi Y'all, > > This is snippet of my code for my testing. > > usr->(dbrlock()) > USR->PASS:= tdenc("ipps") > usr->(dbrunlock()) > cPASS:= tddec(USR->PASS) > > Seems to me cPASS should = "ipps" but, it is "ipps©®Âª¬³ú´¯µ¶Ð²û»è". > > What am I doing wrong? > > Thanks. > > >don< > > | |
Andreas Gehrs-Pahl | Re: tdEnc()/tdDec() on Sun, 10 Feb 2013 12:44:33 -0500 Don, > USR->PASS:= tdenc("ipps") > cPASS:= tddec(USR->PASS) >Seems to me cPASS should = "ipps" but, it is "ipps©®Âª¬³ú´¯µ¶Ð²û»è". >What am I doing wrong? You "encrypted" the string "ipps" to "xxxx" (or whatever). Then you saved this "xxxx" in your database field. But because your database field isn't just four characters long, but (apparently) has a length of 20 characters, the field now contains: "xxxx ". When you "decrypt" this 20-character string, the above string is the result. One (simple, but not optimal) solution would be to use: cPASS:= tddec(trim(USR->PASS)) But this has two problems: 1) it won't work if the original string has any trailing spaces, or 2) if the "encrypted" string does have trailing spaces. The correct way to use such "crypt" functions is to always "encrypt" and "decrypt" the same string (length.) There are several possible ways to do this: 1) If you know the length of the field, pad the string beforehand: USR->PASS := tdenc(PadR("ipps", len(USR->PASS)) 2) Just encrypt the entire field, after filling it: USR->PASS := "ipps" USR->PASS := tdenc(USR->PASS) In either case the return value of tddec(USR->PASS) will then be the same string as if nothing were "encrypted": "ipps ". Hope that helps. Andreas Andreas Gehrs-Pahl Absolute Software, LLC phone: (989) 723-9927 email: Andreas.GP@Charter.net Andreas.Gehrs-Pahl@InterAct911.com Andreas.Gehrs-Pahl@EJusticeSolutions.com Andreas@DDPSoftware.com web: http://www.Aerospace-History.net | |
Raymond Fischbach | Re: tdEnc()/tdDec() on Mon, 11 Feb 2013 13:39:05 +0100 Donald Keating a présenté l'énoncé suivant : > Hi Y'all, > > This is snippet of my code for my testing. > > usr->(dbrlock()) > USR->PASS:= tdenc("ipps") > usr->(dbrunlock()) > cPASS:= tddec(USR->PASS) > > Seems to me cPASS should = "ipps" but, it is "ipps©®Âª¬³ú´¯µ¶Ð²û»è". > > What am I doing wrong? > > Thanks. > > >don< Hello Don, Both Klaus and Andreas are right, it is a question of the string length. But instead of using RTrim() I prefer do do as follows: Saving: USR->PASS := tdEnc(PadR("ipps",20)) if the table field length is 20. Retrieving: cPass := Alltrim(tdDec(USR->PASS)) or RTrim() if you prefer Best regards, Raymond | |
Donald Keating | Re: tdEnc()/tdDec() on Mon, 11 Feb 2013 15:17:34 -0500 Thanks Andreas and Raymond, That got me going in the right direction and I have it working now. >don< On Mon, 11 Feb 2013 13:39:05 +0100, Raymond Fischbach wrote: >Donald Keating a présenté l'énoncé suivant : >> Hi Y'all, >> >> This is snippet of my code for my testing. >> >> usr->(dbrlock()) >> USR->PASS:= tdenc("ipps") >> usr->(dbrunlock()) >> cPASS:= tddec(USR->PASS) >> >> Seems to me cPASS should = "ipps" but, it is "ipps©®Âª¬³ú´¯µ¶Ð²û»è". >> >> What am I doing wrong? >> >> Thanks. >> >> >don< > >Hello Don, > >Both Klaus and Andreas are right, it is a question of the string >length. >But instead of using RTrim() I prefer do do as follows: > >Saving: >USR->PASS := tdEnc(PadR("ipps",20)) if the table field length is 20. > >Retrieving: >cPass := Alltrim(tdDec(USR->PASS)) or RTrim() if you prefer > >Best regards, >Raymond > |