zoukankan      html  css  js  c++  java
  • base64计算

    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个参数,如果你不需要把编码的字符串分隔到多行
    		   
    		   
    		   
    		   
    		   
    		   
    		   
    		   
    		   
    		   
    		   

  • 相关阅读:
    The Future of Middleware and the BizTalk Roadmap
    FW: How to spawn a process that runs under the context of the impersonated user in Microsoft ASP.NET pages
    Strips illegal Xml characters
    luogu P2280 激光炸弹(二维前缀和)
    luogu P2704 炮兵阵地(经典状态压缩DP)
    SP1716 GSS3 Can you answer these queries III (线段树维护最大连续子段和)
    二分图判定、匹配问题
    C++语法综合 | 基于char*设计一个字符串类MyString
    luogu P1044 火车进出栈问题(Catalan数)
    C++设计模式 | 三种设计模式基础
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351008.html
Copyright © 2011-2022 走看看