Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C到Perl的转换HMAC SHA1,数据和密钥_C#_Perl_Hmacsha1 - Fatal编程技术网

C# C到Perl的转换HMAC SHA1,数据和密钥

C# C到Perl的转换HMAC SHA1,数据和密钥,c#,perl,hmacsha1,C#,Perl,Hmacsha1,我想将下面的C代码转换成perl。有人知道怎么做吗?您是否使用hmac_sha1_hex($data,$key)?您是否使用摘要:sha模块?我想用一个键对一些数据进行签名,但是使用perl而不是C using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptography; using System.Web; namespace Amazon.Cba.Signat

我想将下面的C代码转换成perl。有人知道怎么做吗?您是否使用
hmac_sha1_hex($data,$key)?您是否使用摘要:sha模块?我想用一个键对一些数据进行签名,但是使用perl而不是C

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Web;


namespace Amazon.Cba.Signature.Common 
{
    public class SignatureCalculator
    {
        public SignatureCalculator()
        {
        }

    public String calculateRFC2104HMAC(String data, String key)
    {
        String result = null;

        KeyedHashAlgorithm algorithm = new HMACSHA1();

        Encoding encoding = new UTF8Encoding();

        algorithm.Key = encoding.GetBytes(key);

        result =  Convert.ToBase64String(algorithm.ComputeHash(encoding.GetBytes(data.ToCharArray()))); 

            return result;
        }
    }
}

我想这样做:

use MIME::Base64 ();
use Digest::HMAC_SHA1 ();

my $result = MIME::Base64::encode_base64(
    Digest::HMAC_SHA1::hmac_sha1( $data, $key ),
    ''
);
或者,如果需要url安全的base64编码:

my $result = MIME::Base64::encode_base64url(
    Digest::HMAC_SHA1::hmac_sha1( $data, $key ),
);

尽管您也可以同时使用单独的Digest::HMAC和Digest::SHA模块。

这不是c;也许是c#