Question:
I am trying to Sign a SAML assertion. For that reason I need to Sign some XML string with sha1 and using a x509 certificate. I am using a self signed certificate for now. But I am a little confused about how to do so. I tried the following Foxpro code but get the error "Does not support a collection" when trying to assign a value to HashAlgorithm.
Could you please advice if I am doing the right steps? Thanks.
*- Sample VFP source code
close all
clear all
clear
TEXT TO l_CertPrivateKey NOSHOW
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----
ENDTEXT
TEXT TO l_CertPublic NOSHOW
-----BEGIN CERTIFICATE-----
-----END CERTIFICATE-----
ENDTEXT
l_o_Chilkat_PrivateKey = CreateObject('Chilkat_9_5_0.PrivateKey')
l_o_Chilkat_Crypt2 = CreateObject('Chilkat_9_5_0.Crypt2')
l_o_Chilkat_Crypt2.UnlockComponent("Start my 30-day Trial")
l_o_Chilkat_Cert = CreateObject('Chilkat_9_5_0.Cert')
lnSuccess = l_o_Chilkat_PrivateKey.LoadPem(l_CertPrivateKey)
IF (lnSuccess <> 1) THEN
? "Failed l_o_Chilkat_PrivateKey.LoadPem",l_o_Chilkat_PrivateKey.LastErrorText
RELEASE l_o_Chilkat_PrivateKey
CANCEL
ENDIF
lnSuccess = l_o_Chilkat_Cert.LoadPem(l_CertPublic)
IF (lnSuccess <> 1) THEN
? "Failed l_o_Chilkat_Cert.LoadPem", l_o_Chilkat_Cert.LastErrorText
RELEASE l_o_Chilkat
CANCEL
ENDIF
lnSuccess = l_o_Chilkat_Cert.SetPrivateKey(l_o_Chilkat_PrivateKey)
IF (lnSuccess <> 1) THEN
? "Failed l_o_Chilkat_Cert.SetPrivateKey", l_o_Chilkat_Cert.LastErrorText
RELEASE l_o_Chilkat
CANCEL
ENDIF
lnSuccess = l_o_Chilkat_Crypt2.SetSigningCert(l_o_Chilkat_Cert)
IF (lnSuccess <> 1) THEN
? "Failed l_o_Chilkat_Crypt2.SetSigningCert", l_o_Chilkat_Crypt2.LastErrorText
RELEASE l_o_Chilkat
CANCEL
ENDIF
l_o_Chilkat_Crypt2.HashAlgorithm("sha1")
?l_o_Chilkat_Crypt2.SignStringENC("hello")
return
HashAlgorithm is a property, not a method. Setting it to "sha1" should look like this:
l_o_Chilkat_Crypt2.HashAlgorithm = "sha1"
Thanks. Can't believe I made such a simple mistake :)