220
Views
14
Comments
Solved
[CryptoAPI] RSA decryption showing errror - Invalid length for a Base-64 char array or string
cryptoapi
Service icon
Forge asset by João Barata
Application Type
Reactive
Service Studio Version
11.53.20 (Build 61431)
Platform Version
11.16.0 (Build 36096)

Hi 
I am using a RSA_Decrypt fucntion from CyptoAPI where PrivateKey i have saved in DB while encrption.
Sometimes it decrypt successfully sometime it gives error (not sure why) - Invalid length for a Base-64 char array or string 
The content of plainText (While Encryption) is URL input params (single param eg. "TestId=12345")
So how to resolve this error if anyone has some opinion or solution will be higly appreciated.

The solutions i have tried- Directly converting String to Base 64
(Tried with String to Binary conversionof Privatekey and saved in DB while Encryption then convert to text while decryption) 
Many Thanks in advance

2024-09-04 05-41-42
Pratap Singh Naruka
Solution

Hi @Fabio 
I have tried already the solution you providing here already.
The problem was it decrypt sometimes and sometime it gives Base64 error 


Finally i got the issue resolved
So the root cause i found that when in URL - (https://outcrypt.com/Home?Data=**EncryptedParams*) 
For my case EncrptedParams value was "TestId=12345" where base64 conversion problem occured 
so i tried with only encryption for "12345" which means URL changed to -
(https://outcrypt.com/Home?TestId =**EncryptedParams*)
It solved my problem.



Many thanks for your time 
Pratap singh

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


I hope you're doing well.


Try to do that flow in your action: 


I share with you the OML file.


Let me know if this solved your situation.


Kind regards,

FC

Personal_TestOS_FC.oml
2024-09-04 05-41-42
Pratap Singh Naruka

Hi @Fábio Miguel Ferreira Coelho

 
I have used your solution already for last answer this oml file.
Now in the decryption ,I have only cipherText is available at other end (Different screen ) and no other info available as i need to create link encryption that will be distributed among many participants so creating and saving all attributes (PlainText,CipherText,PrivateKey,PublicKey)and saving in DB doesn't make sense.Beacuase if such so then i can use direct DB value without using Encryption and No need to send params encrypted with URL.
I am skeptical for this approach-- I just create one Key i just use it for all encryption time (which is first time when generated saved in DB).
Now saving all other info which you have in your example are just irreravent as i just want decrypt the cipherText with PrivateKey saved in DB 


2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


If you have the Ciphertext you can use it on the "RSA_Decrypt", but you need the Private Key as well. If you save the Private Key on your database or pass it as an input parameter to that action you can have access to the Public Key and use all the actions on the CryptoAPI component.


Let me know if this makes sense to you.


Kind regards,

FC

2024-09-04 05-41-42
Pratap Singh Naruka

I have used Get_PublicKey in Decryption action doesn't seems work.

Finding :- 
I have used ReadKey before Decryption with DB saved Private Key in that scenario it is taking bit longer time to respond and giving error .



I have tried this Solution didn't work for me

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


I need to see the code.

Please create a dummy OML file with the same code that you have.

If you can share a dummy OML with your code it'll be easier to help you find a solution.

2024-09-04 05-41-42
Pratap Singh Naruka

@Fábio Miguel Ferreira Coelho

I have created oml using personal enviorment 
let me know if you get the idea


CryptoAPI_RSA.oml
2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


Thanks for sharing the OML file.


I did some changes in the logic flow and UI.

I think it's working now.

I didn't receive any error in the execution of the flow.


Please see the OML file attached.

Let me know if this suits your needs.


Kind regards,

FC

CryptoAPI_RSA.oml
2024-09-04 05-41-42
Pratap Singh Naruka

@Fábio Miguel Ferreira Coelho 
I have tried your oml got the same error while click on Encrypt URL 2nd time i was getting while testing
Moreover When link copied and pasted in browser didn't responded 

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


It was my mistake, I sent you the wrong OML file. 


Please see the right OML file attached.

Let me know if this suits your needs.


Kind regards,

FC

CryptoAPI_RSA.oml
2024-09-04 05-41-42
Pratap Singh Naruka

Hi @Fábio Miguel Ferreira Coelho 



Still i can not resolve the problem .It still shows error.
It is very strange i have used same approach and not able to decrypt.
I am attaching video for your reference.


However in your Approach you are creating new key every encryption time and saving in DB with CipherText but in my requirement i need to save PrivateKey only once and use it all time as a link copy to clipboard and distributed which means CopyURL can be again clicked meanwhile which means New key will be generated with same Ciphertext and Decryption will fail as while decryption same key expected but with same ciphertext multiple key values exists.


Regards
Pratap

Untitled.mp4
2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


I can't see your video.

I did some changes in the logic flow.

Right now I only save the PrivateKey and the PlainText.

Please see the OML attached.

Let me know if this suits your needs.


Kind regards,

FC

CryptoAPI_RSA.oml
2024-09-04 05-41-42
Pratap Singh Naruka

I suppose i am only facing problem when i am sending encrypted params(e.g.  - testid=12344) in param of URL (https://outcrypt.com/Home?Data=**EncryptedParams*)  and when paste this URL in new tab it gives the error-- 
Invalid length for a Base-64 char array or string.
So i think somthing happens wrong while we send in URL 
I have used method for other then this case it works fine only above scenario causes problem.
Also I noted in some scenarios it works and encrypted url param decrypted at target screen.

Point to note - I have used javaScript method to copy url in clipboard

2022-10-11 21-19-04
Fábio Miguel Ferreira Coelho

Hi Pratap,


The URL pattern of your screen is "TestScreen?PlainText={PlainText}".


So, if I click on "test12345" I go to the TestScreen, and how you'll see the URL is the same:

 


How I built the URL:


I did some modifications to the logic flow.

Please find the OML attached.

Let me know if this solves your issue.


Kind regards,

FC

CryptoAPI_RSA.oml
2024-09-04 05-41-42
Pratap Singh Naruka
Solution

Hi @Fabio 
I have tried already the solution you providing here already.
The problem was it decrypt sometimes and sometime it gives Base64 error 


Finally i got the issue resolved
So the root cause i found that when in URL - (https://outcrypt.com/Home?Data=**EncryptedParams*) 
For my case EncrptedParams value was "TestId=12345" where base64 conversion problem occured 
so i tried with only encryption for "12345" which means URL changed to -
(https://outcrypt.com/Home?TestId =**EncryptedParams*)
It solved my problem.



Many thanks for your time 
Pratap singh

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.