[CryptoAPI] Decrypt - Invalid length for a Base-64 char array or string.

[CryptoAPI] Decrypt - Invalid length for a Base-64 char array or string.

  
Forge Component
(4)
Published on 2015-11-29 by Ricardo Silva
4 votes
Published on 2015-11-29 by Ricardo Silva

Hi,

I'm using EncryptAES256 to encrypt some data. Then an e-mail is send, with an activation link (with parameter the encrypted string). When I decrypt the string on the screen (of the activation link), I get an error as mentioned in the title.

I checked that the generated string, the string in the link and the string passed to the decrypt are all the same (btw, it ends with an "=").

Few days ago it worked, but now I only get this error.

I searched the internet, but could not find a solution for this perticular situaton.

Any ideas?

 

"the string in the link and the string passed to the decrypt are all the same"

Are they the same as the string that was output by the encrypt function ?

Ricardo Silva wrote:

"the string in the link and the string passed to the decrypt are all the same"

Are they the same as the string that was output by the encrypt function ?

yes they are (at least... I checked the first 3 and the last 3 characters...)


Was just re-reading that you also verified that the generated string is the same.


Could you paste one string that's being generated and getting that error here?

sure

from the encrypt:

d+RH5IYMuEJ1n/GixDnRbifwDJ1+c5dBLrol/hjChHdj8H5mdbohyPwo0o09VWirgnXbJN6RPINkuSlcnBxGC1LFxlKATfnstoCptJF6OBI=

link in e-mail:

d+RH5IYMuEJ1n/GixDnRbifwDJ1+c5dBLrol/hjChHdj8H5mdbohyPwo0o09VWirgnXbJN6RPINkuSlcnBxGC1LFxlKATfnstoCptJF6OBI=

passed to the decrypt:

d RH5IYMuEJ1n/GixDnRbifwDJ1 c5dBLrol/hjChHdj8H5mdbohyPwo0o09VWirgnXbJN6RPINkuSlcnBxGC1LFxlKATfnstoCptJF6OBI=


+++> I see now that the second character is changed from a "+" to a space???


Message:
Invalid length for a Base-64 char array or string.
Environment InformationeSpaceVer: 388 (Id=93783, PubId=116430, CompiledWith=9.1.300.0)
RequestUrl: https://os-zakelijk-dev.ee.intern/ToonBuildings_Klant/ActivateAccount.aspx?Activate=d+RH5IYMuEJ1n/GixDnRbifwDJ1+c5dBLrol/hjChHdj8H5mdbohyPwo0o09VWirgnXbJN6RPINkuSlcnBxGC1LFxlKATfnstoCptJF6OBI= (Method: GET)
AppDomain: /LM/W3SVC/1/ROOT/ToonBuildings_Klant-40-131243743034245634
FilePath: F:\Applic\OutSystems\Platform Server\running\ToonBuildings_Klant\ActivateAccount.aspx
Locale: en-US
DateFormat: yyyy-MM-dd
PID: 13856 ('w3wp', Started='11/23/2016 7:06:56 AM', Priv=747Mb, Virt=18291Mb)
TID: 38
Thread Name:
.NET: 4.0.30319.42000
Stack:
Invalid length for a Base-64 char array or string.
   at ssToonBuildings_Klant.RssExtensionCryptoAPI.MssDecryptAES256(HeContext heContext, String inParamCiphertext, String inParamPassword, String& outParamPlaintext)
   at ssToonBuildings_Klant.Flows.FlowMainFlow.ScrnActivateAccount.Preparation(HeContext heContext)
   at ssToonBuildings_Klant.Flows.FlowMainFlow.ScrnActivateAccount.Page_Load(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

There you go.

That's your issue. The + is being dumped directly to the URL which means it will be converted to a space. This is just how URL encoding works.

I recommend that you EncodeUrl() the value when generating the URL, or that you use the platform's functionality to create links instead of doing it by hand. By using a Destination node the URL should be properly encoded.

Ricardo Silva wrote:

There you go.

That's your issue. The + is being dumped directly to the URL which means it will be converted to a space. This is just how URL encoding works.

I recommend that you EncodeUrl() the value when generating the URL, or that you use the platform's functionality to create links instead of doing it by hand. By using a Destination node the URL should be properly encoded.

ok, i'll try that and let you know if it works. 


Thanks already for your help!


Solution

Hans Hol wrote:

Ricardo Silva wrote:

There you go.

That's your issue. The + is being dumped directly to the URL which means it will be converted to a space. This is just how URL encoding works.

I recommend that you EncodeUrl() the value when generating the URL, or that you use the platform's functionality to create links instead of doing it by hand. By using a Destination node the URL should be properly encoded.

ok, i'll try that and let you know if it works. 


Thanks already for your help!


Hi,

The Encode part works! 

I'm not sure about your other solution using the lplatform to make a link. Because the link is put in an e-mail and is fired from that e-mail, I'm not sure if this works. E.g. what to do with the different environments the link has to consider (otap). If you like you can inform me, but for now I'm happy with the other solution.


Solution