Why is my function runs twice

Why is my function runs twice

  

Hello guys,

I created an csharp extension called HashUtils. Basically it encrypt and decrypt the whatever value I might pass in this function. After I publish my extension, then I used it as server action it encrypts my data twice. Here's the sample function of the HashUtils.


public string Encryptor(string value, string salt){

//do some algo here

return encryptedText; //base64 encoded

}

Here's an example on how I use it.

Example scenario:

Card number: 5555123456780000

Correct encrypted value: "XPUH479MA7k="


The Encryptor(cardno, salt) will return this "xBS9MG8/1wfZZjabuq4stQ==" instead of "XPUH479MA7k=". I figure out that the Encryptor runs twice because when I run this Encryptor("XPUH479MA7k=", salt), it will return "xBS9MG8/1wfZZjabuq4stQ=="


I hope you can help me.

Thank you in advance.


-Irvin

Hi Irvin Fabon,

Are you sure you are not Encrypting the Encrypt value of cardno twice in C# function.


Thanks

Raj 

Hi Irvin Fabon,


After reading your case, I felt that the logic might be called twice because of some reason i.e. if the logic is defined in the preparation maybe post back or re-rendering. Please debug the implementation and observer whether the implemented flow is called twice or only once. Apart from that everything seems to be proper.


Regards,

Benjith Sam

Hi Raj,


Thank you for your reply.

Yes, I can say that I am encrypting the not encrypted value. Because I am only using the static value.


-Irvin

Hi Irvin Fabon,

Are you sure you are not Encrypting the Encrypt value of cardno twice in C# function.


Thanks

Raj 



Hi Benjith Sam,

Thank you for your reply.

What do you mean by defined by the preparation? I run the Encryptor function on the event of ButtonOnClick then I use server action for that function. Do I need to refresh the function, because I use it inside the asign like this:


OutCardNumber = Encryptor(cardno, salt)

OutEmailAddress = Encryptor(email, salt)

OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt)


How can I do this asynchronously? I don't know. 


-Irvin

Hi Irvin Fabon,


After reading your case, I felt that the logic might be called twice because of some reason i.e. if the logic is defined in the preparation maybe post back or re-rendering. Please debug the implementation and observer whether the implemented flow is called twice or only once. Apart from that everything seems to be proper.


Regards,

Benjith Sam



Hi Irvin,

If you have that encryptor call in a button click and it only is called once. Because of that the error should be on the extension. Are you sure your extension is correct?

Why create your own encryption? CryptoAPI is not enough for you?

https://www.outsystems.com/forge/component/437/cryptoapi/?Unfollow=False 

If you want share the solution with us and I will take a look into it.

Regards,

Marcelo

Hi Irvin Fabon,

In OutHashComputation you are assigning the encrypted value of OutCardNumber  and OutEmailAddress  so In OutHashComputation variable you will get the intercepted value of encrypted text OutCardNumber.Response + OutEmailAddress.Response.

But the value of OutCardNumber should correct, Can you debug the this action when the value of OutCardNumber is getting changed.

OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt)



Thanks

Raj

Hi Marcelo Ferreira,

Thank you for your response.

What if I call the Encryptor function more than one on onclick of the button. 

For example, assume that we are in the server action.


ButtonOnClick function(){

var OutCardNumber = Encryptor(cardno, salt);

var OutEmailAddress = Encryptor(email, salt);

var OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt);


Because I use the Encryptor like this. Will that assigning practice vary on the response of the function?


-Irvin


Hi Irvin,

If you have that encryptor call in a button click and it only is called once. Because of that the error should be on the extension. Are you sure your extension is correct?

Why create your own encryption? CryptoAPI is not enough for you?

https://www.outsystems.com/forge/component/437/cryptoapi/?Unfollow=False 

If you want share the solution with us and I will take a look into it.

Regards,

Marcelo



Hi Raj,


Yes sir, that's correct. I concatenate them. The OutHashComputation is a combination of the cardNumber, emailAddress and my salt. The Encryptor response is the  encrypted text of whatever value may pass in that function. And also, only the OutCardNumber runs twice. But the OutEmailAddres does not run twice even they are in the same assign.


Regards,

Irvin


Hi Irvin Fabon,

In OutHashComputation you are assigning the encrypted value of OutCardNumber  and OutEmailAddress  so In OutHashComputation variable you will get the intercepted value of encrypted text OutCardNumber.Response + OutEmailAddress.Response.

But the value of OutCardNumber should correct, Can you debug the this action when the value of OutCardNumber is getting changed.

OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt)



Thanks

Raj



Hi Irvin Fabon,


OutSystems also provides a built in PlatformPasswordUtils API which can also be used to generate encrypted string for your input.



Thanks,

Benjith Sam

Solution

Hi Irvin Fabon,

Do one thing create three assignment and assign 

In first assign- OutCardNumber = Encryptor(cardno, salt)

In second-OutEmailAddress = Encryptor(email, salt)

In third assign-OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt)

Debug the action and check the OutCardNumber in every assignment, if in first assignment you are not getting the correct value it means the error is from extension.


Thanks

Raj

Solution

Hi Irvin,

If you want encrypt/decrypt functions, can you please answer Marcelo's question for us? Why not use the existing CryptoAPI component? Also, like Benjith Sam mentions, the PlatformPasswordUtils platform extension already provides one-way hashing functions using two of the most well known algorithms: the outdated MD5 and the more secure and more recent SHA-512.

Why reinvent the wheel, when you already have existing libraries that seem to do exactly what you want?

Also, can you provide us with a sample module where you see this strange behaviour of yours? Based on that we can start to determine whether it's because of OutSystems logic or Extension logic...


Hi Irvin,

Using the same action multiple times doesn't raise any problem. I really think the problem is on your extension. Do you use global variables? Or can you please share it with us? Or try using one of the other encryption methods described on this post.

Regards,

Marcelo 


Irvin Fabon wrote:

Hi Marcelo Ferreira,

Thank you for your response.

What if I call the Encryptor function more than one on onclick of the button. 

For example, assume that we are in the server action.


ButtonOnClick function(){

var OutCardNumber = Encryptor(cardno, salt);

var OutEmailAddress = Encryptor(email, salt);

var OutHashComputation = Encryptor(OutCardNumber.Response + OutEmailAddress.Response, salt);


Because I use the Encryptor like this. Will that assigning practice vary on the response of the function?

Hi Jorge Martins,

Regarding on the Marcelo Ferreira reply, I love to use the existing library. But I will not be able to use that because for some reason, my API is using TripleDESCryptoServiceProvider which I will have to follow their algorithm.


The initialization are correct as I debug the Wrapper of the this action. Because I create a HashWrapper that accepts card, emailadd and salt. And the above screenshot is the action inside that wrapper. Hope you'll get my explanation.


Hi Irvin,

If you want encrypt/decrypt functions, can you please answer Marcelo's question for us? Why not use the existing CryptoAPI component? Also, like Benjith Sam mentions, the PlatformPasswordUtils platform extension already provides one-way hashing functions using two of the most well known algorithms: the outdated MD5 and the more secure and more recent SHA-512.

Why reinvent the wheel, when you already have existing libraries that seem to do exactly what you want?

Also, can you provide us with a sample module where you see this strange behaviour of yours? Based on that we can start to determine whether it's because of OutSystems logic or Extension logic...




Hi guys,


Its now worrking. I just move the Output Parameter OutEmailAddress before the OutHashComputation output parament and I set each output parameter to NullTextIdentifier before I execute the encryptor function. I really appreciate your Ideas. Maybe some other time I will use the  CryptoAPI and PlatformPasswordUtils

Thank you Raj for this https://www.outsystems.com/Forums/discussion/39804/why-is-my-function-runs-twice/#Post143477


Thank you all.

Irvin

Irvin Fabon wrote:

Hi guys,


Its now worrking. I just move the Output Parameter OutEmailAddress before the OutHashComputation output parament and I set each output parameter to NullTextIdentifier before I execute the encryptor function. I really appreciate your Ideas. Maybe some other time I will use the  CryptoAPI and PlatformPasswordUtils

Thank you Raj for this https://www.outsystems.com/Forums/discussion/39804/why-is-my-function-runs-twice/#Post143477


Thank you all.

Irvin

Glad to hear that it helps to solves your issue :)


Thanks

Raj