Skip to content

Instantly share code, notes, and snippets.

@ritou
Created January 22, 2012 16:49
Show Gist options
  • Select an option

  • Save ritou/1657640 to your computer and use it in GitHub Desktop.

Select an option

Save ritou/1657640 to your computer and use it in GitHub Desktop.
Authen::OATH Demo Code
$ cat Authen_OATH_sample.pl
#!/usr/bin/env perl
use strict;
use warnings;
use Authen::OATH;
use MIME::Base32 qw( RFC );
my $oath = Authen::OATH->new();
my $secret = "1234567890";
my $counter = "1";
my $key = MIME::Base32::encode( $secret );
my $totp = $oath->totp( $secret );
my $hotp = $oath->hotp( $secret, $counter );
# output
print "===== OATH OTP Demo =====\n";
print "secret : $secret\n";
print "key(Base32 encoded secret) : $key\n";
print "\n";
print "===== HOTP =====\n";
print "counter : $counter\n";
print "hotp : $hotp\n";
print "\n";
print "===== TOTP =====\n";
print "totp : $totp\n";
print "\n";
$ perl Authen_OATH_issue_TOTP.pl
===== OATH OTP Demo =====
secret : 1234567890
key(Base32 encoded secret) : GEZDGNBVGY3TQOJQ
===== HOTP =====
counter : 1
hotp : 263420
===== TOTP =====
totp : 636562
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment