Ver Mensaje Individual
  #9  
Antiguo 28-01-2025
Jarogo08 Jarogo08 is offline
Miembro
 
Registrado: ene 2025
Posts: 344
Reputación: 2
Jarogo08 Va por buen camino
Yo lo hago así en VB .NET:



Código:
 Public Function HuellaVerifactu_Alta(ByVal IDEmisorFactura As String, ByVal NumSerieFactura As String, ByVal FechaExpedicionFactura As Date, ByVal TipoFactura As String, _
                                       ByVal CuotaTotal As Decimal, ByVal ImporteTotal As Decimal, ByVal Huella As String, ByVal FechaHoraHusoGenRegistro As String) As String

        Dim HuellaVerifactu As String = ""

        Dim Cadena As String = ""
        Cadena += "IDEmisorFactura=" & IDEmisorFactura & "&"
        Cadena += "NumSerieFactura=" & NumSerieFactura & "&"
        Cadena += "FechaExpedicionFactura=" & Format(FechaExpedicionFactura, "dd-MM-yyyy") & "&"
        Cadena += "TipoFactura=" & TipoFactura & "&"
        Cadena += "CuotaTotal=" & CuotaTotal.ToString.Replace(",", ".") & "&"
        Cadena += "ImporteTotal=" & ImporteTotal.ToString.Replace(",", ".") & "&"
        Cadena += "Huella=" & Huella & "&"
        Cadena += "FechaHoraHusoGenRegistro=" & FechaHoraHusoGenRegistro

        HuellaVerifactu = ObtenerHashVerifactu(Cadena)

        Return HuellaVerifactu
    End Function

    Public Function ObtenerHashVerifactu(ByVal cadena As String) As String
        Using sha256 As SHA256 = sha256.Create()
            Dim array As Byte() = sha256.ComputeHash(Encoding.UTF8.GetBytes(cadena))
            Return BitConverter.ToString(array).Replace("-", "").ToUpper
        End Using
    End Function

Como dicen arriba, hay que tener cuidado con los formatos de los campos (sobretodo FechaHoraHusoGenRegistro) porque si no tiene el formato esperado dará error.


Espero que le pueda servir a alguien
Responder Con Cita