Convert Ruby HMAC SHA256 code to C# (Windows 8.1 Universal)

I have the following Ruby code which I'm trying to port to a Windows universal app. Most examples I've found use System.Security.Cryptography which isn't available in the framework.
method = "POST"
uri = "http://api.somewhere.com/events"
data = "my_data"
timestamp = 1423778684
data_utf8 = data.force_encoding("UTF-8").bytes.to_a.map(&:chr).join
message = "#{method}#{uri}#{data_utf8}#{timestamp}"
key = "ABC123"
checksum = Digest::HMAC.hexdigest(message, key, Digest::SHA256)
puts checksum
# => 83f47bcd10c7360614bb8a858786eb588be3494f1e9bf8a1769bd5f6fff0a3b8
The 'Digest::HMAC.hexdigest' being the line giving me trouble. Thanks!

Hi,
I do not very familiar with the Ruby code. But seem you want to create hash value in windows store app. If so, you can use the Windows.Security.Cryptography namespaces to do that. There are some codes you can try:
string stringToSign = "Whatever message you wish to sign";
string hashKey = "The key you want to sign it with.";
MacAlgorithmProvider macAlgorithmProvider = MacAlgorithmProvider.OpenAlgorithm("HMAC_SHA256");
BinaryStringEncoding encoding = BinaryStringEncoding.Utf8;
var messageBuffer = CryptographicBuffer.ConvertStringToBinary(stringToSign, encoding);
IBuffer keyBuffer = CryptographicBuffer.ConvertStringToBinary(hashKey, encoding);
CryptographicKey hmacKey = macAlgorithmProvider.CreateKey(keyBuffer);
IBuffer signedMessage = CryptographicEngine.Sign(hmacKey, messageBuffer);
string hashedString = CryptographicBuffer.EncodeToBase64String(signedMessage);
More information you can refer to the link below:
https://msdn.microsoft.com/en-us/library/windows.security.cryptography.core.macalgorithmprovider.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a
href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

Similar Messages

  • Warning: Apple's hmac-sha256.c sample code appears to be PPC only

    There is a big-endian issue in Apple's hmac-sha256.c code ... it appears not to be portable on Intel machines. So if you're hosting your portal site on an Intel machine (whether it's a Mac or a Dell), you're likely not going to be able to get Apple's shell script sample to work.
    Apple's shell script requires that you compile the seconds.c, urlencode.c, and hmac-sha256.c source code files. While seconds.c and urlencode.c produce the same output (given the same input) on both a PPC Mac and an Intel Mac, hmac-sha256.c does not. I have looked at this two different ways (just by running the code and from within gdb) and I'm pretty satisfied that there is an endian issue within the code (the code favors a big-endian machine ... like the PowerPC ... over a little-endian machine ... like a CoreDuo Mac/Dell server).
    There is probably a straightforward fix, but I am not a sha encryption expert, so I will have to do my homework over the weekend. The fix would likely involve #ifdefing the code in the usual way. The only diffuculty is going to be in finding the dependency. If you're using the Java/Perl/Python stuff, you should be utterly safe (those languages work at a higher level of abstraction and take endianess into account).
    I hope this was helpful.

    Well, I keep learning new things.
    It looks like the SHA-256 algorithm itself thinks in a big-endian way.
    http://en.wikipedia.org/wiki/SHA-1
    I am not sure what the impact is on Apple's implementation ... cyrptography is not my thing, but I'm willing to learn.
    MacBook Pro   Mac OS X (10.4.8)   I lied. I'm running Leopard

  • How can i print all the contect of the code in sapscript window ? ?

    how can i print all the contect of the code in sapscript window ? ?

    Hi,
    Do you mean that you want to print the ABAP code to SAPscrip form ?
    Svetlin

  • Bar Code Scanning for Windows Phone 8.1

    Hi,
    I need to find proper way how to scan bar codes in Windows Phone 8.1 or in universal app. I found out that there is native class BarcodeScanner available only for client apps and not for WP. I also find 3rd party library zxing.net, which is not working very
    well on WP 8.1. I have done really deep research, but I have not found any single working solution for WP 8.1, so I would like to ask for your help in finding of library with which I will be able to scan barcodes on WP 8.1.
    Thank you.

    If you don't need a universal App you could build a Silverlight 8.1 App and use the old Camera APIs which work nicely with ZXing.Net. I have done so myself.
    As for Windows 8 and Universal Apps - you would have to implement a CustomSink for the Video Stream, extract Frames from there and pipe those though a recognition library. So far there seems to be no ready made solution that offers this.
    So right now using the old APIs would be my suggestion.

  • Convert char to ascii code and vice versa

    HI
    Is there any function module to convert char to ascii code and vice versa.
    Thanks in advance

    Hi,
    be careful if you have unicode running in your system. URL_ASCII_CODE_GET is platform-dependent so it will return the internal HERX representation of the character in your system - which is hopefully and in most cases ASCII.
    Under unicode, we use double-byte characters here. I tried this function and the result CHAR_CODE is '00' regardless what character I specify for TRANS_CHAR. But the coding is so simple I corrected resultig in this sample code:
    [P]
    convert p_form to ASCII (internal) representation
      DATA:
        l_ofs TYPE syfdpos,
        l_len TYPE sy-linsz,
        l_ascii TYPE i.
      FIELD-SYMBOLS:
        <x> TYPE x.
      l_len = STRLEN( p_ascii ).
      DO l_len TIMES.
        l_ofs = sy-index - 1.
        ASSIGN p_ascii+l_ofs(1) TO <x> CASTING.
        l_ascii = <x>.
        WRITE: l_ascii.
      ENDDO.
    [/P]
    Here, for each character of string p_ascii, the internal (ASCII) representation is determined and written to the output list.
    Regards,
    Clemens

  • Error encountered while signing. Windows cryptographic service provider reported an error. Object not found. Error code:2148073489. Windows 7, Adobe Reader XI, Symantec PKI, Smart Card and CAC. I have seen other threads for this error but none have a reso

    Error encountered while signing. Windows cryptographic service provider reported an error. Object not found. Error code:2148073489. Windows 7, Adobe Reader XI, Symantec PKI, Smart Card and CAC. I have seen other threads for this error but none have a resolution. Any help would be appreciated.
    Sorry for the long title, first time poster here.

    This thread is pretty old, are you still having this issue?

  • Printer is asking for an user acces code instead of windows login and password?

    I have been seeing the HP printers asking(LaserJet M4555 MFP, LaserJet 500 color MFP M575 etc) for user access code instead of windows login and password.
    One thing i have noticed  is that when this happens there is a slight change in the EWS page configuration at security -> access control.The device administrator tabe is unchecked as you can see below ehen this happens
    Have tried cold resetting the printer and restore facory settings but this does not works and some thimes it does works for a while but the issue is returing back.
    We do not need this access code promt instead we need the usual windows login and password that used be there originally.
    alsothis is how the settings look like after a cold reset somtimes when it does not  asks for user access code , the problem is cold rese does lways works and it reverts back ois original settings

    @munish259272 
    ‎Thank you for using HP Support Forum. I have brought your issue to the appropriate team within HP. They will likely request information from you in order to look up your case details or product serial number. Please look for a private message from an identified HP contact. Additionally, keep in mind not to publicly post ( serial numbers and case details).
    If you are unfamiliar with the Forum's private messaging please click here to learn more.
    Thank you,
    Omar
    I Work for HP

  • Error code 80070002 on windows 8.1 updates

    When i try to update windows it keeps failing.
    I have looked in to this and found its HP NULL PRINT thats the problem.
    Error code 80070002
    How can i resolve this ??

    Hi @stuart40,
    Welcome to the HP Forums!
    I noticed that you are getting the error code 80070002 on windows 8.1 updates, with your HP Photosmart 5520 printer. I am sorry to hear this but happy to help!
    Just to confirm, are you trying to update the printer software, or the Windows Operating System in general?
    Is your computer an HP computer?
    In the meantime, here is a post, I had found regarding this issue, Windows 8.1 Update Error Code: 0x8007002. Which I am assuming is an Operating System issue, not a printer issue.
    If it is the Windows updates you are trying to resolve, and the post does not help, please contact Microsoft Support.
    Thank you for posting, and happy new year!  
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • On my G5 mac at work, I am getting - don't know what to call it - looks like extraneous matrix type code around prompt windows and in applications. Sometimes I will get large shapes of colors, yellows, magentas, cyans. Anyone else experience this?

    On my G5 mac at work, I am getting - don't know what to call it - looks like extraneous matrix type code around prompt windows and in applications. Sometimes I will get large shapes of colors, yellows, magentas, cyans. Anyone else experience this?
    I will attach a recent screen shot of a print window I opened and the extra code is above and below the window. There are matrix type blocks of code and then lines under the window. I get this all the time and it is getting worse.
    Any help to get rid of it would be appreciated.
    Thanks
    TatteredSkull

    It's likely the Video card, or possibly heat.
    At the Apple Icon at top left>About this Mac.
    Then click on More Info>Hardware and report this upto *but not including the Serial#*...
    Hardware Overview:
    Machine Name: Power Mac G5 Quad
    Machine Model: PowerMac11,2
    CPU Type: PowerPC G5 (1.1)
    Number Of CPUs: 4
    CPU Speed: 2.5 GHz
    L2 Cache (per CPU): 1 MB
    Memory: 10 GB
    Bus Speed: 1.25 GHz
    Boot ROM Version: 5.2.7f1
    Get Temperature Monitor to see if it's heat related...
    http://www.macupdate.com/info.php/id/12381/temperature-monitor
    iStat Menus...
    http://bjango.com/mac/istatmenus/
    And/or iStat Pro...
    http://www.islayer.com/apps/istatpro/
    If you have any temps in the 70°C/160°F range, that's likely it.

  • Error code: 0xc0000001 file: \windows\system32\winload.efi missing or contains errors

    I have a new 2 month old(Aug 2014) hp eliteone 800 all in one computer running win 8.1 64bit. i have two  1 tb hard drives raid configuration. left computer on for an afternoon and when I came back it was off mysteriously. tried to turn on and it
    attempted to repair and was never able to repair. hp sent a new windows 8 software to install, they said os was corrupt. installed three times now i get error code: 0xc0000001 file: \windows\system32\winload.efi  missing or contains errors. hp said installation
    disc probably corrupt and sent me another. installed twice with same result, error code: 0xc0000001 file: \windows\system32\winload.efi  missing or contains errors. This began after the computer was just one month old and after i had placed 300-400
    gb of my personal data from other computers on it. I need all of these files so can't just recover/delete all of the files on the computer, although i have read that that may be my only solution? If i do recover will the files still be on the second hard drive??
    can you help with this problem?? thanks.

    Hi Richard,
    Did you try to repair or reinstall the system when you insert the new media?
    Have you tried to carry out a system recovery, which will restore your system back to factory defaults and how was the result?
    In addition, I suggest you use the new installation media to do a clean install(full format the old system).
    How to perform a clean installation of Windows
    http://windows.microsoft.com/en-IN/windows-8/clean-install
    Note: If you have important personal data, remember to insert your drive into another computer to backup your personal data before you do any operation.
    Karen Hu
    TechNet Community Support

  • T-code of the window where it asks for evaluation path.

    Hi,
    I want the T-code of that window where it asks for evaluation path. I want to generate the report in OM

    Hi,
    If you are creating repoert through HIS tool, you can use OODS T code to declare the Evaluation path.
    Tomesh

  • Help:convert form 6i to load it on windows mobile?

    hi,
    i have a form 6i and i want to see it on windows mobile 6.0, is there a tool that convert the form to load it on windows mobile.
    i convert the form 6i to form 10g but i didn't succeeded to load the form on windows mobile, i have search for a jinitiator or a jre but i didn't retrieve it.
    is there a way to load a form on windows mobile? if not is there another solution?
    sincerely
    Edited by: user8735714 on Aug 26, 2009 12:39 AM
    Edited by: user8735714 on Aug 26, 2009 11:11 PM

    Please be aware that just because something can be made to seemingly work does not mean that Oracle will support it. Problems which may occur on unsupported platforms or with unsupported configurations will not be considered defects unless the issue is reproducible on a supported configuration.
    Neither Citrix environments or mobile environments are supported for use with Oracle Forms.

  • How to execute a Command Prompt command from J2SE code executing on Windows

    How to execute a Command Prompt command from J2SE code executing on Windows??
    Please help me

    [http://java.sun.com/docs/books/tutorial/getStarted/]
    ~

  • How do i convert my Photoshop CS 4 version from Windows to Mac

    How do i convert my Photoshop CS 4 version from Windows to Mac.

    You are not likely to be able to convert your CS4 license/version from Windows to Mac.  Platform conversions are only supported for current releases, which would be CS6.  Creative Cloud subscriptions allow for either or both platforms to be supported.

  • How can I turn off compatibility with 7.1 when labview 8 converts my 7.1 code?

    Hi,
    I just loaded LV8 on my mac. It converted/compiled my app code to 8. While doing that, it changed many of my constants to hidden controls to maintain combabtibility with 7.1. I really don't care about 7.1 anymore. Is there a way to turn this off so I can re-compile the code and keep it the way it is?
    Obviously, I am new to LV but I don't see a reason for keeping the compatibility with 7.1 if my lab is going to 8.
    Any thoughs, comments, or critisims would be appreciated.
    tarek316

    The particular issue you're talking about isn't necessarily "compatibility" with LabVIEW 7.1...it's actually ensuring that your VIs behave the same in 8.0 as they did in 7.1.  As described in that dialog box, a change was made in LabVIEW 8.0 regarding how VI diagrams are compiled in regards to Case Structures with cases that will never run.  If you are using case structures with constants wired to their selectors purely to keep VIs in memory at particular points in your code, then you should heed the advice given in the context help for the created control and use a Static VI Reference in your code instead of a subVI in a case structure.  If you are using case structures with constants wired to their selectors to comment out code, perhaps you should use the Diagram Disable structure instead.
    -D 
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

Maybe you are looking for