You are viewing limited content. For full access, please sign in.

Question

Question

Encoding an URL with btoa and atob

asked on December 5, 2017

Good afternoon,

 

I'm working on a project in which I'd like to encode a URL coming from a Workflow email to look something like:

https://myurl.com?encode=dGVzdA==

and then I'd be doing the decoding from the form. The form does not have to be as secure, it's just for mormatting purposes that I don't want the actual information in the URL.

Problem is that I don't know how to decode it when coming from Workflow. I don't want to create additional hidden fields just to encode the parts that I need.

Any ideas or suggestions?

Thank you,

Raul Gonzalez

0 0

Answer

SELECTED ANSWER
replied on December 5, 2017

So the way id do this is use the SDK Script activity with the following code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;
    using System.Net;


    public class Script1 : RAScriptClass100
    {
        /// <summary>
        /// 64 bit encode method
        /// </summary>
        ///
        static public string EncodeTo64(string toEncode) {
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
            string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }

        protected override void Execute()
        {
            string baseVal = GetTokenValue("baseValue").ToString();
            string encodeVal = EncodeTo64(baseVal);
            SetTokenValue("encodeValue",WebUtility.UrlEncode(encodeVal));
        }
    }

To make this work create 2 tokens called baseValue and encodeValue. Add the value you want to encode into baseValue then call the SDK activity.

1 0

Replies

replied on December 5, 2017

What method are you using to encrypt the parameters, its pretty easy to write a decryption algorithm in JavaScript that pulls the parameter value from the url.

0 0
replied on December 5, 2017

Thanks Aaron,

For the decryption part I was thinking in using the example as shown below, I just can't think of a way to encrypt it coming from the Workflow. 

The workflow sends out an email using an Email Activity that says:

URL: http://www.something.com?parameter=test

I want for it to send it like:

URL: URL: http://www.something.com?parameter=dGVzdA==

and I can do the decription in the form. Again, this is not for anything secure, it's just to keep things in a certain format.

$( document ).ready(function() {

  alert(btoa("test"));
  
  alert(atob('dGVzdA=='));
  
});

 

0 0
SELECTED ANSWER
replied on December 5, 2017

So the way id do this is use the SDK Script activity with the following code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Text;
    using Laserfiche.RepositoryAccess;
    using System.Net;


    public class Script1 : RAScriptClass100
    {
        /// <summary>
        /// 64 bit encode method
        /// </summary>
        ///
        static public string EncodeTo64(string toEncode) {
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
            string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }

        protected override void Execute()
        {
            string baseVal = GetTokenValue("baseValue").ToString();
            string encodeVal = EncodeTo64(baseVal);
            SetTokenValue("encodeValue",WebUtility.UrlEncode(encodeVal));
        }
    }

To make this work create 2 tokens called baseValue and encodeValue. Add the value you want to encode into baseValue then call the SDK activity.

1 0
replied on December 14, 2017

Aaron,

We are delaying the part of the project for which I wanted to use the encoding so I wasn't able to fully try it. Thanks for sharing and I'll give your code a try as soon as I get back into that piece of the project.

Thanks again,

Raul Gonzalez

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.