[CryptoAPI] Encrypt data and persist in the DB

[CryptoAPI] Encrypt data and persist in the DB

  
Forge Component
(13)
Published on 17 Oct (2 days ago) by Ricardo Silva
13 votes
Published on 17 Oct (2 days ago) by Ricardo Silva

Hi all,


    I am trying to persist a field from a form, but I get an error when I save this data to the DB. Here ir the error:


Id:
22324c65-23e2-4023-8fbd-d7c067d290d5
Time of Log:
2016-11-04 15:12:58
eSpace:
PlanMedicoJubilados
Tenant:
Users
User:
 (2)
Session Id:
1710b97a-7a53-4733-bc4b-3a75fe18ab5d
Server:
OS70376DEV101123
Module:

Message:


Content is not allowed in prolog.


Environment InformationeSpaceVer: 49 (Id=82, PubId=75, CompiledWith=10.0.105.0)
RequestUrl: https://claropr-dev.outsystemsenterprise.com/PlanMedicoJubilados/AgregarFamiliar.jsf (Method: POST)
ClassLoader: ModuleClassLoader for Module "deployment.PlanMedicoJubilados.war:main" from Service Module Loader(1727538349)
FilePath: /PlanMedicoJubilados/AgregarFamiliar.jsp
ClientIp: 196.28.57.7
Locale: en-US
DateFormat: yyyy-MM-dd
PID: 20431 ('20431@OS70376DEV101123', Started='10/12/16 9:40:44 AM', Priv=584Mb, Virt=3763Mb)
TID: 226
Thread Name: default task-22
JRE: 25.92-b14
Stack:
Content is not allowed in prolog.
org.xml.sax.SAXParseException: Content is not allowed in prolog.
   at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
   at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
   at ardo.crypto.CryptoBackend.getPublicSpecFromXML(Unknown Source)
   at ardo.crypto.CryptoBackend.rsa_encrypt(Unknown Source)
   at outsystems.noscryptoapi.actions.ActRSAEncrypt.mosRSAEncrypt(Unknown Source)
   at osplanmedicojubilados.referencesproxy.rssextensioncryptoapi.actions.ActRSAEncrypt.mosRSAEncrypt(Unknown Source)
   at osplanmedicojubilados.actions.ActRSAEncrypt.executeRSAEncrypt(Unknown Source)
   at osplanmedicojubilados.managedbean.flowmainflow.ScrnAgregarFamiliar.commandSave(Unknown Source)
   at osplanmedicojubilados.managedbean.flowmainflow.ScrnAgregarFamiliar.btn11Click(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at com.sun.el.parser.AstValue.invoke(AstValue.java:292)
   at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
   at org.apache.jasper.el.JspMethodExpression.invoke(JspMethodExpression.java:68)
   at outsystems.hubedition.webwidgets.uicomponent.utils.MethodExpressionEventListener.invokeAction(Unknown Source)
   at outsystems.hubedition.webwidgets.uicomponent.utils.MethodExpressionClickEventListener.processClickEvent(Unknown Source)
   at outsystems.hubedition.webwidgets.uicomponent.utils.ClickEvent.processListener(Unknown Source)
   at javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
   at outsystems.hubedition.webwidgets.uicomponent.os_controls.WebBlockInstanceComponent.broadcast(Unknown Source)
   at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
   at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
   at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
   at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
   at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130)
   at outsystems.hubedition.webwidgets.BaseRequestStartupFilter.doFilter(Unknown Source)
   at osplanmedicojubilados.RequestStartupFilter.doFilter(Unknown Source)
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
   at outsystems.hubedition.webwidgets.filters.HttpContextFilter.doFilter(Unknown Source)
   at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60)
   at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132)
   at io.undertow.servlet.handlers.FilterHandler.handleRequest(FilterHandler.java:85)
   at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:61)
   at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
   at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
   at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:56)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:45)
   at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:63)
   at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58)
   at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70)
   at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
   at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261)
   at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:247)
   at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:76)
   at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:166)
   at io.undertow.server.Connectors.executeRootHandler(Connectors.java:197)
   at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:759)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)

Heres is the message error in the app(sounds like a whitespace before the string is causing the problem, but dont know how to fix it ):


Hey there Tomas,


From the error that you're getting it seems to me that you are passing a key in the wrong format. The key needs to be in XML format.

Did you generate the key using CryptoAPI? or are you trying to use a key from somewhere else?

Best regards,

Ricardo Silva

Hi Ricardo,


       The key was generated filling the Public Key field with data. Thanks for the clue, but I have to create a longer key because I get this message: RSA keys must be at least 512 bits long. How can I create a Key using a data enough longer?


Thanks,

Tomás