Welcome! Log In Create A New Profile

Advanced

[WB27] - Function to encrypt string in browser code

Posted by pao 
pao
[WB27] - Function to encrypt string in browser code
December 27, 2022 12:33PM
I can't find any WEBDEV function to encrypt one string in browser code.
Anyone know how to do it in WEBDEV?

Regards

Paulo Oliveira
Re: [WB27] - Function to encrypt string in browser code
December 27, 2022 02:43PM
Hi Paulo,
but would a Browser encrypt function be safe?
Most modern encrypt implementations that I have found - for js - use node.js.
So the safe thing to do is let WEBDEV Server code take care of the encrypt/decrypt and pass it to the Browser.

Regards
Steven Sitas
pao
Re: [WB27] - Function to encrypt string in browser code
December 27, 2022 05:12PM
One of the requirements from our client is to have in memory encription for some type of data.
I can do it using one AJAX procedure but it would be nice if we can reduce the number of calls to the server.

Regards

Paulo Oliveira
Re: [WB27] - Function to encrypt string in browser code
January 04, 2023 01:15PM
Hie Paulo,

here the answer from my new friend "chat gpt"

Here is an example of a simple function that can be used to encrypt a string in browser code using the JavaScript CryptoJS library:

function encrypt(message, key) {
var encrypted = CryptoJS.AES.encrypt(message, key);
return encrypted.toString();
}


To use this function, you will need to include the CryptoJS library in your HTML file by adding a script tag to your HTML code.

Here is an example of how you could use the encrypt function:

var message = "Hello, World!";
var key = "secret key";
var encrypted = encrypt(message, key);
console.log(encrypted); // output: "U2FsdGVkX1/pZ8VOAe+6OZTzFvQ2UWx6UzhM6UyO6Kk="


HTH MD

regards Michael
pao
Re: [WB27] - Function to encrypt string in browser code
January 04, 2023 01:42PM
Thanks Michael

Regards

Paulo Oliveira
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: