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);
In reply to String to Byte array by kpaxian25
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |