zjzc01:/root# cat aa.pl
use URI::Escape;
use URI::Escape qw(uri_unescape);
use MIME::Base64;
use Digest::HMAC_SHA1;
$xx="GET&%2F&AccessKeyId%3DZ7bph8ZgNR4oMNVh%26Action%3DDescribeRegions%26Format%3DJSON%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0%26TimeStamp%3D$SDATEX%26Version%3D2014-05-26";
print "$xx is $xx
";
$str=Digest::HMAC_SHA1::hmac_sha1("$xx",'fQIJzvxOXZuc1AhLxtVMz0q2Nd7zkj&');
$Signature = encode_base64($str);
print "$Signature
";
$head='http://ecs.aliyuncs.com/?';
#+ 替换为%20 =替换为%3d
$Signature = uri_escape("$Signature");
print "$Signature is $Signature
";
zjzc01:/root# perl aa.pl
$xx is GET&%2F&AccessKeyId%3DZ7bph8ZgNR4oMNVh%26Action%3DDescribeRegions%26Format%3DJSON%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0%26TimeStamp%3D%26Version%3D2014-05-26
I3GHM2wC+3i40vWpXMRox7AK1WE=
$Signature is I3GHM2wC%2B3i40vWpXMRox7AK1WE%3D%0A
回车是 %0a
原因是base64计算的时候没有加第2个参数
zjzc01:/root# cat aa.pl
use URI::Escape;
use URI::Escape qw(uri_unescape);
use MIME::Base64;
use Digest::HMAC_SHA1;
$xx="GET&%2F&AccessKeyId%3DZ7bph8ZgNR4oMNVh%26Action%3DDescribeRegions%26Format%3DJSON%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0%26TimeStamp%3D$SDATEX%26Version%3D2014-05-26";
print "$xx is $xx
";
$str=Digest::HMAC_SHA1::hmac_sha1("$xx",'fQIJzvxOXZuc1AhLxtVMz0q2Nd7zkj&');
$Signature = encode_base64($str,"");
print "$Signature
";
$head='http://ecs.aliyuncs.com/?';
#+ 替换为%20 =替换为%3d
$Signature = uri_escape("$Signature");
print "$Signature is $Signature
";
zjzc01:/root# perl aa.pl
$xx is GET&%2F&AccessKeyId%3DZ7bph8ZgNR4oMNVh%26Action%3DDescribeRegions%26Format%3DJSON%26RegionId%3Dregion1%26SignatureMethod%3DHMAC-SHA1%26SignatureNonce%3DNwDAxvLU6tFE0DVb%26SignatureVersion%3D1.0%26TimeStamp%3D%26Version%3D2014-05-26
I3GHM2wC+3i40vWpXMRox7AK1WE=
$Signature is I3GHM2wC%2B3i40vWpXMRox7AK1WE%3D
encode_base64($str, $eol);
Encode data by calling the encode_base64() function. The first argument is the string to encode. The second argument is the line-ending sequence to use. It is optional and defaults to "
". The returned
encoded string is broken into lines of no more than 76 characters each and it will end with $eol unless it is empty. Pass an empty string as second argument if you do not want the encoded string to be broken
into lines.
编码数据通过调用 encode_base64() 函数,第一个参数是需要编码的字符串。
第2个参数是行结束,它是可选的 默认是
o
返回的编码的字符串被分隔成一行不超过76个字符
传递一个空字符串作为第2个参数,如果你不需要把编码的字符串分隔到多行