kpaxian25 has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to write the below C# code in perl, what is the C# equivalent for Convert.ToByte(key.Text.Substring(i * 2, 2), 16); in perl.
Any insight is much appreciated.
Thanks.
Perl code I got so far # convert key to a byte array// convert key to a byte array int len = key.Text.Length / 2; if (len == 0) throw new ApplicationException("key must be provid +ed"); byte[] k = new byte[len]; for (int i = 0; i < len; i++) { k[i] = Convert.ToByte(key.Text.Substring(i * 2, 2) +, 16); } summaryText += "key=" + key.Text.Trim() + "\r\n\r\n";
$key="AJDAHSDJ213718327DSFSDJFHSDKFJ87348171837"; #example $len=length($key) / 2; if($len == 0) { print"Key must be provided";} else { for($i=0;$i<$len;$i++) { $k[$i]= ? }
Also how do you pass the byte array as a key value to sha256 hash, Join the array values ? $key_value=@k; $digest=hmac_sha256_base64($data,$key_value);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String to Byte array
by BrowserUk (Patriarch) on Sep 19, 2013 at 16:42 UTC | |
by toolic (Bishop) on Sep 19, 2013 at 16:51 UTC | |
by kpaxian25 (Novice) on Sep 20, 2013 at 21:29 UTC | |
by kpaxian25 (Novice) on Sep 20, 2013 at 21:12 UTC | |
|
Re: String to Byte array
by hdb (Monsignor) on Sep 19, 2013 at 19:03 UTC | |
by BrowserUk (Patriarch) on Sep 19, 2013 at 20:50 UTC | |
by kpaxian25 (Novice) on Sep 20, 2013 at 21:11 UTC | |
|
Re: String to Byte array
by Tux (Canon) on Sep 19, 2013 at 16:34 UTC | |
by erictrarner (Initiate) on Oct 11, 2014 at 08:01 UTC |