Encrypting & Decryption of information

Hi Guys,
Just wanted to know if anyone has an idea how to do this:
I need encryption ability on information going into the database, but then I also need to decrypt it as well if an admin or the user needs to change any information.
I’ve tried SALT but this can’t be decrypted (so I’ve found out)

Do any one have any ideas, as I’ve hit a brick wall on this :slight_smile:

Hi Peter,
Hashing with salt is a one-way function and it cannot be decrypted. That’s why this type of encryption is used for storing passwords - you cannot decrypt them, you just compare hashes.

Please check the following discussion:

ok so I’m guessing there is no way of encrypting the data and decrypting it.
Thanks for the reply Teodor :slight_smile:

What are you trying to achieve?

As i explained the idea of encryption is to not be able to decrypt it - it only works one way -> encrypt with salt, which creates a hash.

What I need is to somehow encrypt peoples address, due to privacy, but then still have the ability for them to change it if they move.

I believe there are ways of doing this but it will need some custom code. Here is a useful reference to using openssl encryption/ decryption in PHP which may help

NOTE. Never tried this myself
https://www.the-art-of-web.com/php/two-way-encryption/

Actually, looking into what wappler has to offer, i see there is “Encrypt with password” and “Decrypt with password” in the Crytographic options, have you tried them?

1 Like

no, not yet, that might be a work around and use their login password.
Good call I’ll have a look into that, lol back to long days and late night web designing :wink:

1 Like

I used Mcrypt in a PHP/MySQL project a few years ago, but it was removed in PHP 7.2. There is an alternative - Sodium - but I haven’ t used it. I don’t think it would be a trivial matter to use this with Wappler. Perhaps not possible at all.

I would be interested to know more about the encrypt/decrypt options @Hyperbytes mentioned.

1 Like

Set up a quick test.
https://briananddebbi.uk/crypto.php

Enter text into the form.

Click process

Three notifications will show

Blue: original text
Green: encrypted form
Red: decrypted

Seems to work perfectly

Here is the server action doing it:

image

3 Likes

Thanks @Hyperbytes - that was a quick test/demo!

I think it’s using Mcrypt - in which case I don’t think it will work with PHP 7.2. If this correct, it would be good to know if this feature will be updated.

Yes, just checked with 7.0, 7.1, 7.2, 7.3

Anything past Version 7.0 causes 500 error

“Call to undefined function lib\core\mcrypt_create_iv()”

I think it was deprecated pre-7.2 and finally removed in that version. So - probably not a good idea to use it. I hope there will be a replacement at some point.

7.1/ 7.2 is causing error, seems 7.0 is last working version in wappler

Recommendation now is to use openssl_encrypt as detailed in my earlier post, perhaps this could be integrated in to wappler @patrick as a replacement?

This is indeed something that needs to be updated, but have to be careful not to break current implementation since openssl encryption is different then the mcrypt encryption.

1 Like

Perhaps continue to offer both versions under different titles in the Crytographic menu ?

That will probably be the solution if we don’t find a way to decrypt the old mcrypt encrypted data, but prefer to just replace the old with the new encryption. Will do some tests, there are a lot of encryption methods in openssl, probably one is compatible with the old mcrypt.

3 Likes

You can do this.

Encrypt your data as required to the DB, to display use a repeater with a setvalue step inside the server action calling the data. Apply decrypt to the setvalue step and then on the page bind it, the data will then be displayed decrypted.

1 Like

Here’s the same thing discussed in another topic:

Hi Dave
The issue is not how to do it mechanically, the issue is which cryptographic method to use which is compatible with all versions of PHP. The inbuilt encrypt/decrypt with password doesn’t work after php v7.0