pquerna / otp

TOTP library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

can I use a secret string containg specail characters?

Nogawan opened this issue · comments

I want to generate a password so I used the function in totp package GenerateCodeCustom() as

   func getPassword(token_shared_secret string) string{
	opts := totp.ValidateOpts{}
	opts.Period = 30
	opts.Skew = 1
	opts.Digits = 10
	opts.Algorithm = otp.AlgorithmSHA512
	
	var password string
	t := time.Now()
	password, err := totp.GenerateCodeCustom(token_shared_secret,t,opts)
	if err != nil {
		panic(err)
	}
	return password
}

var password string = getPassword(myID+subfix)

I needed to change some options like that cuz the main purpose is to make a HTTP POST to some URL and they directed me to make the password as an 10-digit time-based one, time step X is 30secs ,T0 is 0 and use HMAC-SHA-512 for the hash function.

the parameter I put as myID+subfix is a concatenated string with an email address and an English string.

The problem is that email address contains special charters @ and . (at and dot). And I failed to get the password with the error sign

panic: Decoding of secret as base32 failed.

So I tried modifying the GenerateCodeCustom() function in hotp package
I changed the line (line no.84)

secretBytes, err := base32.StdEncoding.DecodeString(secret)

as

secretBytes := []byte(secret)

At least I succeeded to get a ten-digit time-based password but I don't think it is correct one because the server keep sending me http 401 response. I think it's not a proper way, I may need to do something.

Can you let me know how can I solve this ?

commented

wx20181013-144314 2x

replace these secret operations with

secretBytes := []byte(secret)

I'm sorry but I already tried that but I failed XD

Can you please make a small self-contained test case that is failing for to achieve what you are describing? I'm having a hard time following what the issue is with otp?