NetTalk Central

Author Topic: Strange behaviour of NetEncryptString and NetDecryptString  (Read 2670 times)

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Strange behaviour of NetEncryptString and NetDecryptString
« on: August 26, 2024, 12:09:07 AM »
I use NetEncryptString and NetDecryptString to decrypt passwords. So they won't show there initial value in the database.
Example:
Usr:Wachtwoord = NetEncryptString(lWachtwoord,len(lWachtwoord),'xxxxxxx')
And to show it again or to validate the paswords
lWachtwoordString = usr:Wachtwoord
lWachtwoord = NetDecryptString(lWachtwoordString,len(lWachtwoordString),'xxxxxxx')

But not all of the paswords can be decrypted.
These are some values and the indication wheter they can be decrypted:
- AA34&&&^    yes
- AA$A8nt56Y   yes
- $$34er$         no
- A3gh2$          yes
- B3gh2$          no

Can someone tell me why some values cannot be decrypted?

Regards
Joep

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11245
    • View Profile
Re: Strange behaviour of NetEncryptString and NetDecryptString
« Reply #1 on: August 26, 2024, 07:16:32 PM »
I suspect you are not getting the len quite right.

First, I'm assuming all these are strings, not cstrings. (You can't use cstrings for binary values, and encrypted strings are binary values.)

second, len(string) returns declared length of the string, not clipped length. (And you can't clip because the encrypted password might end in chr(32).
So you need to track, and store, the length of encrypted fields. OR have a fixed-length string with a fixed length (including trailing spaces).

joep

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
    • Email
Re: Strange behaviour of NetEncryptString and NetDecryptString
« Reply #2 on: September 16, 2024, 01:34:25 AM »
Hi Bruce,

I have got it working. Like you said I needed the length of the string.
So len(string) did not work. I used stringtheory to determine the length en stored it in the database.
And NetdecryptString with the wrigth length gave me in all examples the same string back.
Thanks for pointing the wrigth direction to me.

Regards Joep