문제

My understanding (which may obviously be wrong) is that the Authen::OATH module is compatible with the totp codes generated by the Google Authenticator App. But it doesn't work for me, whereas a similar bit of ruby code does. We're a perl shop here and it would help if anyone could point me in the right direction to save me from digging through both libraries line by line.

This ruby works compatibly:

require 'rubygems'

require 'rotp'

secret = "bqagf6ohx4rp3a67"

puts ROTP::TOTP.new(secret).now.to_s

This perl does not:

use Authen::OATH;

my $oath = Authen::OATH->new();

my $totp = $oath->totp(" bqagf6ohx4rp3a67" );

print "$totp\n";
도움이 되었습니까?

해결책

It's not very clear from the documentation, but Authen::OATH expects the unencoded passwords to totp and hotp. If that's not an option, you could try decode_base32 from Convert::Base32

use Convert::Base32;
use Authen::OATH;

my $oath = Authen::OATH->new();

my $totp = $oath->totp( decode_base32( "bqagf6ohx4rp3a67" ) );

print "$totp\n";
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top