keycard-go/hexutils/hexutils.go

28 lines
435 B
Go
Raw Normal View History

2018-09-27 09:23:12 +00:00
package hexutils
import (
"encoding/hex"
"fmt"
"log"
"regexp"
)
func HexToBytes(s string) []byte {
s = regexp.MustCompile(" ").ReplaceAllString(s, "")
b := make([]byte, hex.DecodedLen(len(s)))
_, err := hex.Decode(b, []byte(s))
if err != nil {
log.Fatal(err)
}
return b[:]
}
func BytesToHexWithSpaces(b []byte) string {
return fmt.Sprintf("% X", b)
}
func BytesToHex(b []byte) string {
return fmt.Sprintf("%X", b)
}