Yo tengo una rutina pero al parecer no encripta correctamente la cadena original
loRsa.LittleEndian = 0
lorsa.Charset = "utf-8"
loRsa.EncodingMode = "base64"
strSello = loRsa.SignStringENC(strOriginal,"SHA-2") &&tambien funcino con SHA-256
N = loCert.SerialNumber
noCertificado = SubStr(N,02,1)+SubStr(N,04,1)+SubStr(N,06,1)+SubStr(N,08,1)+SubStr(N,10,1)+;
SubStr(N,12,1)+SubStr(N,14,1)+SubStr(N,16,1)+SubStr(N,18,1)+SubStr(N,20,1)+;
SubStr(N,22,1)+SubStr(N,24,1)+SubStr(N,26,1)+SubStr(N,28,1)+SubStr(N,30,1)+;
SubStr(N,32,1)+SubStr(N,34,1)+SubStr(N,36,1)+SubStr(N,38,1)+SubStr(N,40,1)+;
SubStr(N,42,1)+SubStr(N,44,1)+SubStr(N,46,1)+SubStr(N,48,1)+SubStr(N,50,1)
Certificado = SubStr(loCert.GetEncoded(), 1, Len(loCert.GetEncoded()) - 2)
quien puede tener otra rutina diferente, utilizo ChiltKat

DESCARGA SOFTWARE PARA FACTURA ELECTRONICA DE AQUI.
Facturacion, Validacion, Addendas, Librerias de programacion, etc.
CARTA PORTE V3.1
ECODEX TIENE ESTOS NUEVOS DATOS DE CONTACTO :
Comercializacion y Ventas - Evelia Vicke evicke@ecodex.com.mx 33-16-03-03-48
Soporte - Humberto Guerrero soporte@ecodex.com.mx 33-34-90-46-03
.
Como crear el Sello con SHA256 en Visual Foxpro
-
- Mensajes: 60
- Registrado: Mié Nov 21, 2012 4:04 pm
-
- Mensajes: 164
- Registrado: Vie Nov 25, 2011 3:12 pm
Re: Como crear el Sello con SHA256 en Visual Foxpro
Aquí la Tienes
Rutina para sellar la cadena original en VFP usando el Chidkat para los CFDI 3.3
Rutina para sellar la cadena original en VFP usando el Chidkat para los CFDI 3.3
Código: Seleccionar todo
Function SelloDigital
Parameters ArchivoCer,ArchivoKey,PasswordKey,strCadenaOriginal
Local loPkey
Local lnSuccess
Local lcPkeyXml
Local loRsa
Local lcFileData
Local lcBase64Sig
Local loCert
If not File(ArchivoCer )
Return "ERROR: No existe el archivo Certificado " +ArchivoCer
EndIf
If not File(ArchivoKey )
Return "ERROR: No existe el archivo Key " +ArchivoCer
EndIf
If Empty(PasswordKey)
Return "ERROR: Contraseña de llave pribada vacia"
EndIf
* Objetos
loPkey = CreateObject('Chilkat.PrivateKey')
loRsa = CreateObject('Chilkat.Rsa')
loCert = CreateObject('Chilkat.Cert')
* Load the Certificado
loCert.LoadFromFile(ArchivoCer)
* Load the private key from an RSA PEM file: * loPkey.LoadPemFile("myKey.pem")
lnSuccess = loPkey.LoadPkcs8EncryptedFile(ArchivoKey, PasswordKey)
IF (lnSuccess <> 1) THEN
return "Error No se pudo abrir el archivo Key: " + ArchivoKey + " con el password que tiene el sistema registrado"
ENDIF
* Get the private key in XML format:
lcPkeyXml = loPkey.GetXml()
* Desbloquea componente
lnSuccess = loRsa.UnlockComponent("RSAT34MB34N_7F1CD986683M")
* Error
IF (lnSuccess <> 1) THEN
return "Error No se pudo desbloquer el componente ChilKat"
ENDIF
* Import the private key into the RSA component:
lnSuccess = loRsa.ImportPrivateKey(lcPkeyXml)
* OpenSSL uses BigEndian byte ordering:
loRsa.LittleEndian = 0
lorsa.Charset = "utf-8"
loRsa.EncodingMode = "base64"
* Creates an RSA digital signature by hashing strToBeHashed and then signing the hash.
* The hash algorithm is specified by hashAlgorithm, which may be
* "SHA-1", "MD5", "MD2", "SHA-256", "SHA-384", or "SHA-512".
* The recommended hash algorithm is "SHA-1".
* The digital signature is returned as an encoded string,
* where the encoding is specified by the EncodingMode property.
mSelloDigital = loRsa.SignStringENC(strCadenaOriginal,"SHA-256")
If EMPTY(mSelloDigital)
Return "Error No se pudo obtenre el sello digital "
ENDIF
N = loCert.SerialNumber
mnoCertificado = SubStr(N,02,1)+SubStr(N,04,1)+SubStr(N,06,1)+SubStr(N,08,1)+SubStr(N,10,1)+;
SubStr(N,12,1)+SubStr(N,14,1)+SubStr(N,16,1)+SubStr(N,18,1)+SubStr(N,20,1)+;
SubStr(N,22,1)+SubStr(N,24,1)+SubStr(N,26,1)+SubStr(N,28,1)+SubStr(N,30,1)+;
SubStr(N,32,1)+SubStr(N,34,1)+SubStr(N,36,1)+SubStr(N,38,1)+SubStr(N,40,1)+;
SubStr(N,42,1)+SubStr(N,44,1)+SubStr(N,46,1)+SubStr(N,48,1)+SubStr(N,50,1)
mCertificado = SubStr(loCert.GetEncoded(), 1, Len(loCert.GetEncoded()) - 2)
If empty(mCertificado)
Return "Error No se pudo obtener el certificado"
EndIf
If empty(mNoCertificado)
Return "Error No se pudo obtener el Número del certificado"
EndIf
Return "OK"
Saludos
Halcón Divino
Monterrey
Nuevo León
México
Halcón Divino
Monterrey
Nuevo León
México
-
- Mensajes: 8
- Registrado: Mar Ene 04, 2011 4:58 pm
Re: Como crear el Sello con SHA256 en Visual Foxpro
Hola Halcon Divino, estoy programando en VFP9 y lo hago mediante OpenSSL y me da error de sello, ¿Alguna sugerencia? Utilizo tu metodo que alguna vez publicaste.
- Dado
- Mensajes: 15980
- Registrado: Mar Jul 06, 2010 7:56 pm
Re: Como crear el Sello con SHA256 en Visual Foxpro
Revisa la libreria DLL de aqui, esa DLL sella y timbra en un solo paso tus comprobantes y te ahorra muchisimo tiempo de programacion
ADDENDAS? VALIDACION? CODIGO PARA PROGRAMAR TU PROPIA SOLUCION? TODO LO TENEMOS EN WWW.VALIDACFD.COM VISITANOS !!