Excel Parser

Procesamiento local — ningún dato sale de tu navegador

Macros VBA

Fragmentos para anonimizar columnas en Excel con SHA-256, equivalentes al procesamiento de esta herramienta.

Windows
Requiere .NET — usa System.Security.Cryptography.
Function SHA256(text As String) As String
    Dim utf8 As Object
    Dim bytes() As Byte
    Dim hash() As Byte
    Dim i As Integer
    Dim result As String
    Dim sha As Object

    Set utf8 = CreateObject("System.Text.UTF8Encoding")
    bytes = utf8.GetBytes_4(text)

    Set sha = CreateObject("System.Security.Cryptography.SHA256Managed")
    hash = sha.ComputeHash_2(bytes)

    For i = LBound(hash) To UBound(hash)
        result = result & LCase(Right("0" & Hex(hash(i)), 2))
    Next i

    SHA256 = result
End Function

Function NormalizarTexto(ByVal texto As String) As String
    texto = Trim(texto)
    texto = Replace(texto, ".", "")
    texto = Replace(texto, "-", "")
    texto = LCase(texto)

    NormalizarTexto = texto
End Function

Sub AnonimizarColumnaSHA256()
    Dim rango As Range
    Dim celda As Range
    Dim textoNormalizado As String

    Set rango = Selection

    For Each celda In rango
        If Not IsEmpty(celda.Value) Then
            textoNormalizado = NormalizarTexto(CStr(celda.Value))
            celda.Value = SHA256(textoNormalizado)
        End If
    Next celda
End Sub
macOS
Usa shasum del shell vía MacScript.
Function SHA256_Mac(ByVal texto As String) As String
    Dim comando As String
    Dim resultado As String

    ' Escapar comillas simples para shell
    texto = Replace(texto, "'", "'''")

    ' Usa printf %s para NO agregar salto de línea
    comando = "printf %s '" & texto & "' | shasum -a 256 | awk '{print $1}'"

    resultado = MacScript("do shell script " & Chr(34) & comando & Chr(34))

    SHA256_Mac = resultado
End Function

Function NormalizarTexto(ByVal texto As String) As String
    texto = Trim(texto)
    texto = Replace(texto, ".", "")
    texto = Replace(texto, "-", "")
    texto = LCase(texto)

    NormalizarTexto = texto
End Function

Sub AnonimizarColumnaSHA256_Mac()
    Dim celda As Range
    Dim textoNormalizado As String

    For Each celda In Selection
        If Not IsEmpty(celda.Value) Then
            textoNormalizado = NormalizarTexto(CStr(celda.Value))
            celda.Value = SHA256_Mac(textoNormalizado)
        End If
    Next celda
End Sub