Last active
January 22, 2021 20:33
-
-
Save mrminus/100f51317f1e86190e43d5319a2f9199 to your computer and use it in GitHub Desktop.
GOLANG Array Hash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author: Jason Harper, Uber Technologies, Inc. | |
// Date: September 11, 2020 | |
// Version: 1 | |
// Notes: A prototype SHA256 hashing script, using a shared secret key | |
// Notes: reading data from a single list of SSN or DL, or whatever, and a two column CSV | |
// Notes: secret key data is just for testing | |
// Notes: this program helped me understand some basic GO concepts | |
package main | |
import ( | |
"crypto/hmac" | |
"crypto/sha256" | |
"encoding/csv" | |
"encoding/hex" | |
"fmt" | |
"os" | |
//"strconv" | |
) | |
type CsvLine struct { | |
Column1 string | |
Column2 string | |
} | |
func main() { | |
var count int | |
count = 1 | |
lines, err := ReadCsv("ssn-and-dl.csv") //obv need to have this file created ahead of time | |
if err != nil { | |
panic(err) | |
} | |
// Loop through lines & turn into object | |
for _, line := range lines { | |
data := CsvLine{ | |
Column1: line[0], | |
Column2: line[1], | |
} | |
key := "5C646D6E58DECE7203C28AD290E2249E42455A3F856E2297291880B37B50B9DA" //not a real-key | |
ssn := hmac.New(sha256.New, []byte(key)) | |
dl := hmac.New(sha256.New, []byte(key)) | |
if data.Column1 == "raw_ssn" { | |
fmt.Println("") | |
} else { | |
ssn.Write([]byte(data.Column1)) | |
dl.Write([]byte(data.Column2)) | |
ssn_sha := hex.EncodeToString(ssn.Sum(nil)) | |
dl_sha := hex.EncodeToString(dl.Sum(nil)) | |
fmt.Println("SSN Result:",count, ssn_sha + " " + "DL Result:",count , dl_sha) | |
count=count +1 | |
} | |
} | |
} | |
// ReadCsv accepts a file and returns its content as a multi-dimentional type | |
// with lines and each column. Only parses to string type. | |
func | |
ReadCsv(filename string) ([][]string, error) { | |
// Open CSV file | |
f, err := os.Open(filename) | |
if err != nil { | |
return [][]string{}, err | |
} | |
defer f.Close() | |
// Read File into a Variable | |
lines, err := csv.NewReader(f).ReadAll() | |
if err != nil { | |
return [][]string{}, err | |
} | |
return lines, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment