高分求帮忙, HMACSHA1有关问题
高分求帮忙, HMACSHA1问题
我不会perl,我要做一个加密的程序。
请哪位高手帮我下,告诉我digest最后的值是多少
或者大家给我一个C#的 可以和下面同样值的函数
$challenge'='27c81c82d52252c2fd0567e859df3c31';
$key='xyzxyz';
$ascii_key = pack "H*", $portal_secret;
$login_params='res=success'+'&challenge=$challenge'
my $digest = `echo -n "$login_params" | openssl dgst -sha1 -hmac "$ascii_key"`;
$digest =~ s/[\n\r\s]+$//;
$digest= substr($digest,-40,40);
我用的是,可惜结果不样,请高手帮忙
public static string HashUTF8(string keyStr,string sourceStr)
{
byte[] key = System.Text.Encoding.UTF8.GetBytes(keyStr);
HMACSHA1 hmac = new HMACSHA1(key);
// Convert the input string to a byte array and compute the hash.
byte[] data = hmac.ComputeHash(Encoding.UTF8.GetBytes(sourceStr));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
------解决方案--------------------
很多错误:
( ! ) Warning: pack(): Type H: illegal hex digit x in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit y in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit z in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit x in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit y in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit z in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Notice: Use of undefined constant s - assumed 's' in C:\wamp\www\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
( ! ) Fatal error: Undefined constant 'n\r\s' in C:\wamp\www\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
代码稍微改了些编译错误,目前是
我不会perl,我要做一个加密的程序。
请哪位高手帮我下,告诉我digest最后的值是多少
或者大家给我一个C#的 可以和下面同样值的函数
$challenge'='27c81c82d52252c2fd0567e859df3c31';
$key='xyzxyz';
$ascii_key = pack "H*", $portal_secret;
$login_params='res=success'+'&challenge=$challenge'
my $digest = `echo -n "$login_params" | openssl dgst -sha1 -hmac "$ascii_key"`;
$digest =~ s/[\n\r\s]+$//;
$digest= substr($digest,-40,40);
我用的是,可惜结果不样,请高手帮忙
public static string HashUTF8(string keyStr,string sourceStr)
{
byte[] key = System.Text.Encoding.UTF8.GetBytes(keyStr);
HMACSHA1 hmac = new HMACSHA1(key);
// Convert the input string to a byte array and compute the hash.
byte[] data = hmac.ComputeHash(Encoding.UTF8.GetBytes(sourceStr));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
------解决方案--------------------
很多错误:
( ! ) Warning: pack(): Type H: illegal hex digit x in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit y in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit z in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit x in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit y in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Warning: pack(): Type H: illegal hex digit z in C:\wamp\www\test.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
2 0.0000 243768 pack ( ) ..\test.php:5
( ! ) Notice: Use of undefined constant s - assumed 's' in C:\wamp\www\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
( ! ) Fatal error: Undefined constant 'n\r\s' in C:\wamp\www\test.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 243264 {main}( ) ..\test.php:0
代码稍微改了些编译错误,目前是
<?php
$challenge='27c81c82d52252c2fd0567e859df3c31';
$portal_secret='xyzxyz';
$ascii_key = pack("H*", $portal_secret);
$login_params='res=success'+'&challenge=$challenge';