Decrypt the email address from cryptstring id=<%= escapeUrl(cryptString(targetData.email)) %> | Community
Skip to main content
Level 5
August 21, 2024
Solved

Decrypt the email address from cryptstring id=<%= escapeUrl(cryptString(targetData.email)) %>

  • August 21, 2024
  • 1 reply
  • 3257 views

Hi there,

"I am passing the recipient's email through a survey URL generated in Adobe Campaign and need to decrypt this email address. I'm using a JavaScript function to extract the email parameter from the URL, decrypt it, and send the data to a table. However, the decrypted string is still appearing as an encrypted string for some reason."

 

?email_id=<%= escapeUrl(cryptString(targetData.email)) %>

 


function decryptString(encryptedEmail) {
// Implement your decryption logic here
return encryptedEmail; // Placeholder: returning the input as-is
}

// Function to decrypt and extract the email address from the URL
function getEmailFromUrl() {
const params = new URLSearchParams(window.location.search);
const encryptedEmail = params.get('email_id');

// Decrypt the email address using the decryptString function
const email = decryptString(encryptedEmail);
return email;
}

// Function to validate the survey, set values, and submit the form
function validate() {
// Get the email address from the URL
const email = getEmailFromUrl();

if (!email) {
alert("Error: Email address is missing.");
return false;
}

 

if (isValid) {
// Set the email address to the "Email_Address" path
document.controller.setValue("/ctx/FOD_SurveyResponse/@Email_Address", email);

// Submit the form if validation passed
document.controller.submit('next', '_self', 'next');
}

return isValid;
}

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rvnth

Hello @rvnth 

In Javascript activity you can just use this

 

const decryptedEmail=decryptString(ctx.vars.email_id); 


Hi @_manoj_kumar_ ,

 

Thank you for your assistance. The code below successfully enabled me to decrypt the email string and store it in the corresponding schema column.

.

 

ctx.vars.key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc"; ctx.vars.Email_Address = ctx.vars.Email_Address.toString(); ctx.FOD_SurveyResponse.@Email_Address = decryptString(ctx.vars.Email_Address, ctx.vars.key256Bytes);

 

 

1 reply

Manoj_Kumar
Community Advisor
Community Advisor
August 21, 2024

Hello @rvnth  This is because you have created a function with similar name it is not doing anything.

 

remove this code:

function decryptString(encryptedEmail) { // Implement your decryption logic here return encryptedEmail; // Placeholder: returning the input as-is }

 

Also, I would suggest you to some other identifier than email 

Manoj     Find me on LinkedIn
rvnthAuthor
Level 5
August 22, 2024

Hi @_manoj_kumar_ ,

 

Thank you for your response. After removing decryptString, I'm encountering an error stating that decryptString is not defined in the code block below. Since the Adobe decryptString function isn't working here, is there an alternative way to decrypt?

function getEmailFromUrl() { const params = new URLSearchParams(window.location.search); const encryptedEmail = params.get('email_id'); // Decrypt the email address using the decryptString function const email = decryptString(encryptedEmail); return email; }

Thank you in advance. 

 

Is it possible to decrypt this directly at the attribute level within the Schema, or do I need to send only the decrypted string data?

rvnthAuthor
Level 5
September 6, 2024

Also, share the screenshot of the webapp with activities used and highlight the activity where this code is used.


Hi @_manoj_kumar_  ,

 

 

I’m still working on this myself but am having trouble understanding a few things. I’ve outlined them below, and I’d appreciate your help:

 

When should we use /ctx/vars/variable_name?

 

I’ve declared a few variables in the properties section of a WebApp and am using those in the URL to dynamically render the form.

 

I’m trying to access the first parameter in the URL, which I’ve encrypted using a 256-bit key. I’ve successfully accessed the encrypted string using the function below:

function getEmailFromUrl() { var params = new URLSearchParams(window.location.search); var encodedEmailId = params.get('email_id'); if (!encodedEmailId) { return null; // No email_id found } // Decode the URL-encoded string var decodedEmailId = decodeURIComponent(encodedEmailId); // Replace special URL-encoded characters with their original values decodedEmailId = decodedEmailId.replace(/%2B/g, '+') .replace(/%2C/g, ',') .replace(/%2F/g, '/') .replace(/%3A/g, ':') .replace(/%2D/g, '-') .replace(/%3B/g, ';') .replace(/%2E/g, '.') .replace(/%40/g, '@') // Keep @ decoding .replace(/%3D/g, '='); // Remove the leading '@' and trailing '=' if present if (decodedEmailId.startsWith('@')) { decodedEmailId = decodedEmailId.slice(1); // Remove leading '@' } if (decodedEmailId.endsWith('=')) { decodedEmailId = decodedEmailId.slice(0, -1); // Remove trailing '=' } // Log the final decoded and cleaned email ID console.log("Final Decoded Email ID:", decodedEmailId); return decodedEmailId; // Return the cleaned email ID } function validate() { var questions = [ { name: "Question1", errorMessage: "Please select at least one option for Feature1." }, { name: "Question1", errorMessage: "Please select at least one option for Feature2." }, { name: "Question1", errorMessage: "Please select at least one option for Feature3." } ]; var isValid = true; questions.forEach(function(question) { var questionInputs = document.querySelectorAll('input[name="' + question.name + '"]'); var selectedAnswers = document.querySelectorAll('input[name="' + question.name + '"]:checked'); if (questionInputs.length > 0) { if (selectedAnswers.length === 0) { alert(question.errorMessage); questionInputs[0].focus(); isValid = false; // Set to false if validation fails } else { selectedAnswers.forEach(function(answer) { document.controller.setValue('/ctx/FOD_SurveyResponse/@' + question.name, answer.value); }); } } }); if (isValid) { // Submit the form document.controller.submit('next', '_self', 'next'); } return isValid; // Return validation result } // ]]>

 

Now, can you explain how to access this encrypted string and pass it to the decryptString function within the JavaScript activity of the WebApp? I’m also working on a function that sets values upon form submission:

 

var emailId = getEmailFromUrl(); // Extract email ID from URL var key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc"; // 256-bit key var email_id = decryptString(emailId, key256Bytes); // Decrypt email ID


What I’m trying to achieve is to capture the customer’s response (typically a value between 1-10) and send that response to a backend table and specific column. I’m currently using document.controller.setValue('ctx/Fod_Survey/Question1') in client side, which works fine for capturing the response upon clicking on the submit button, but I’m struggling with the decryption part.

 

 

I am using the function below in a JavaScript file, but it seems that the email address is not being decrypted successfully. Although the question response is submitted, and I'm directed to the Thank You page, the encrypted emailId retrieved from the URL—whether decrypted or not—is not being passed to the email_address column in the table.

function valid() { // Get email ID from URL var emailId = getEmailFromUrl(); var key256Bytes = "fFKwuLzAsmMYoY6f1lxpMKuFSTWLCgdc"; // Decrypt the email ID var email_id = decryptString(emailId, key256Bytes); // Initialize isValid var isValid = true; // Validate the email ID if (!emailId || !email_id) { alert("Error: Email ID is missing or invalid."); isValid = false; } // Continue with validation if email is valid if (isValid) { // Set the value and submit the form document.controller.setValue("/ctx/FOD_SurveyResponse/@Email_Address", email_id); document.controller.submit('next', '_self', 'next'); } // Return the validation status return isValid; }

Thanks in advance for your help!