Archived Forum Post

Index of archived forum posts

Question:

WebService with authentication

Apr 18 '13 at 10:15

Hi I'm programming with your activex in VFP9 and I need help.

I want to call a webservice (https://servicos.portaldasfinancas.gov.pt:701/sgdtws/documentosTransporte), with authentication certificate PFX.

For each transmission must be generated one unique symmetric key that is encrypted based on a digital certificate in accordance with the RSA algorithm and encoded in Base64

my code: locrypt= Createobject('Chilkat.Crypt2') lorsa = Createobject('Chilkat.Rsa') loSoapReq = Createobject('Chilkat.Xml') Cert = Createobject('Chilkat.Cert') lcUsername = "505622670/1" _lcPassword = "astuto4088"

lorsa.Charset = "utf-8" LOrsa.ImportPublicKey(PubKey.GetXml) loRsa.EncodingMode = "base64" loRsa.LittleEndian = 1 lorsa.VerboseLogging = 1 lorsa.OaepPadding = 0 locrypt.VerboseLogging = 1 loCrypt.CryptAlgorithm = "aes" loCrypt.CipherMode = "ebc" loCrypt.KeyLength = 128 loCrypt.CharSet = "utf-8" loCrypt.PaddingScheme = 0 loCrypt.EncodingMode = "base64" loHttp = CreateObject('Chilkat.Http') loReq = CreateObject('Chilkat.HttpRequest') loreq.HttpVerb = "POST" loReq.Path = "/sgdtws/documentosTransporte" loReq.AddHeader("SOAPAction","envioDocumentoTransporte") lcDomain = "https://servicos.portaldasfinancas.gov.pt" lnPort = 701 lnSsl = 1

?lohttp.SetSslClientCertPfx("c:EnvioGuiasTestesWebservices.pfx","TESTEwebservice","DGITA")

lcSecretKey = SUBSTR(lcUsername,7,2)+SUBSTR(TIME(),1,2)+; STR(INT(RAND()89)+10,2)+SUBSTR(TIME(),4,2)+; STR(INT(RAND()89)+10,2)+SUBSTR(TIME(),7,2)+; STR(INT(RAND()*89)+10,2)+SUBSTR(TIME(1),10,2) lcNonce = loRsa.EncryptStringENC(lcSecretKey,0)

?lcNonce

End code ****

The Nonce variable is empty.

What am I doing wrong?

Best regards from Portugal, Hugo Coelho