| OAuth-Lite documentation | Contained in the OAuth-Lite distribution. |
OAuth::Lite::SignatureMethod::HMAC_SHA1 - HMAC_SHA1 signature method class;
# Consumer side
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
token_secret => 'bar',
);
my $signature = $method->sign($base_string);
# Service Provider side
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => 'foo',
token_secret => 'bar',
);
unless ($method->verify($base_string, $signature)) {
say "Signature is invalid!";
}
HMAC_SHA1 signature method class.
Class method. Returns this method's name.
say OAuth::Lite::SignatureMethod::HMAC_SHA1->method_name;
# HMAC_SHA1
say OAuth::Lite::SignatureMethod::HMAC_SHA1->build_body_hash($content);
my $method = OAuth::Lite::SignatureMethod::HMAC_SHA1->new(
consumer_secret => $consumer_secret,
token_secret => $bar,
);
Generate signature from base string.
my $signature = $method->sign($base_string);
Verify signature with base string.
my $signature_is_valid = $method->verify($base_string, $signature);
unless ($signature_is_valid) {
say "Signature is invalid!";
}
Lyo Kato, lyo.kato _at_ gmail.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.
| OAuth-Lite documentation | Contained in the OAuth-Lite distribution. |
package OAuth::Lite::SignatureMethod::HMAC_SHA1; use strict; use warnings; use base 'OAuth::Lite::SignatureMethod'; __PACKAGE__->method_name('HMAC-SHA1'); use Digest::SHA; use MIME::Base64;
sub build_body_hash { my ( $class, $content ) = @_; my $hash = MIME::Base64::encode_base64(Digest::SHA::sha1($content)); $hash =~ s/\n//g; return $hash; }
sub sign { my ($self, $base_string) = @_; my $key = $self->secrets_as_key(); my $sign = MIME::Base64::encode_base64(Digest::SHA::hmac_sha1($base_string, $key)); chomp $sign; $sign; }
1;