zoukankan      html  css  js  c++  java
  • Cool____hmac_sha256 in php and c# differ

    转http://stackoverflow.com/questions/699041/hmac-sha256-in-php-and-c-differ Hello this is my PHP code: hash_hmac( "sha256", utf8_encode( $filename ), utf8_encode( $password ) ); and this is my C# code: var hmacsha256 = new HMACSHA256( Encoding.UTF8.GetBytes( password ) ); hmacsha256.ComputeHash( Encoding.UTF8.GetBytes( filename ) ); unfortunately both results differ. Can anyone give me a hint? c# php hashcode link|edit|flag asked Mar 30 '09 at 21:11 tanascius 11k11737 90% accept rate 1 Answer active oldest votes up vote 4 down vote accepted My C# is not the best but i got it to work, what you need to do is to convert your byte array results to hex. PHP $hash = hash_hmac( "sha256", utf8_encode("Filename"), utf8_encode("Password")); echo $hash; // 5fe2ae06ff9828b33fe304545289a3f590bfd948ca9ab731c980379992ef41f1 C# string password = "Password"; string filename = "Filename"; var hmacsha256 = new HMACSHA256(Encoding.UTF8.GetBytes(password)); hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(filename)); foreach(byte test in hmacsha256.Hash) { Console.Write(test.ToString("X2")); } // 5FE2AE06FF9828B33FE304545289A3F590BFD948CA9AB731C980379992EF41F1
  • 相关阅读:
    Mac终端编写c语言程序方法
    X-code最常用快捷键
    类方法和实例方法区别
    一、SQL语句中的增、删、查、改
    从零开始,学习web前端之HTML基础
    图片 自适应 容器大小
    Java第二天 数据类型
    Java 第一天
    javascript的基础知识
    JavaScript(一)
  • 原文地址:https://www.cnblogs.com/adodo1/p/4327919.html
Copyright © 2011-2022 走看看