[CryptoAPI] Invalid syntax on line 9

Forge Component
Published on 3 Mar by Ricardo Silva
21 votes
Published on 3 Mar by Ricardo Silva

Hello everyone, 

I'm having this error message when trying to encrypt a text using a public key generated on an authentication server here in the company. As you can see in the OML file, I created a server action with RSA_Encrypt and put the public key in the PublicKey parameter and a text 123456 in the PlainText parameter. When running WebScreen the error "Invalid syntax on line 9" is displayed on the screen. Can you help me with this?

If you need the public key I am using is:

----- BEGIN PUBLIC KEY -----


HCQbbfNMjoB8BDOcGi63R / wlxl4SAQZp5J5BTPtAI5h6Ym9j7 + IJYC8qZyZzq7Z6

mhOAlDWztPT + Eidn4tF2NzIXLaQRNJMxpvIArZs8Oigh7s3WqDPH2ENPKxECbiQ0

sbzDMZ0Cy98BCsHadmGY8sszQjT63dSwAgOhmvQdxABwDtC / w955XDWOAjKYX + Xd

yyr / aNVKEuM / E8Vn / 0JyiDow4EgDgBpR4hyXELUiyZFBHT3AyNvik / qHrlwGbAwn



----- END PUBLIC KEY -----

The OML file is attached.


Hi Thiago,

CryptoAPI actions don't directly support PEM encoded RSA keys. You'll need to convert them to XML notation using RSA_PrivateKeyFromPEM (yes, I'm aware the name doesn't make it obvious you should use it for a public key).

I don't remember if I tried it with a public key directly, but think it should work.

Please give it a go and let me know if you're having issues so I can look further into it.


Hi Ricardo,

I tried to use RSA_PrivateKeyFromPEM, but I did not succeed.

However, since you said that I needed to convert my PEM file to XML I made this conversion through https://superdry.apphb.com/tools/online-rsa-key-converter

With a public key generated for testing it worked. But with my public key generated by the authentication platform did not work, I'm not sure if the error could be in PKCS format or in another detail that I have not seen.

I keep trying here.


What exactly didn't work with the key generated by the application?

Was it the online tool for converting that failed? Or was CryptoAPI which then failed to use the converted XML key?

Hi Ricardo,

Sorry for the delay in coming back here.

So I had some evolution from yesterday to today.

I was able to use the RSA_PrivateKeyFromPEM.

I believe that the manipulation of private and public keys is already ok.

But I believe I'm having trouble with the encryption type.

I believe that the error reported in the topic has already been remedied. I'll open another post, because I think the error is already related to something else.

Thank you so far Ricardo.