Skip to content

Instantly share code, notes, and snippets.

@0xC0D3D00D

0xC0D3D00D/saman_totp.go

Last active Nov 14, 2019
Embed
What would you like to do?
Saman Bank TOTP implementation
package main
import (
"bytes"
"crypto/hmac"
"crypto/sha1"
"encoding/binary"
"encoding/hex"
"fmt"
"time"
)
func main() {
token := "6D436B6A54FF6916E7611CA8168C4E94210790F4"
pin := "123456"
keyHex := []byte(token+pin)
key := make([]byte, len(keyHex)/2)
_, err := hex.Decode(key, keyHex)
if err != nil {
panic(err)
}
now := time.Now().UnixNano() / int64(60*time.Second)
buffer := new(bytes.Buffer)
binary.Write(buffer, binary.BigEndian, now)
mac := hmac.New(sha1.New, key)
mac.Write(buffer.Bytes())
sum := mac.Sum(nil)
b := sum[len(sum)-1] & 15
fmt.Println(b)
fmt.Println(binary.BigEndian.Uint32(sum[b:b+4]) % 100000000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.