Signing a string

Author Message
WeBeScript

  • Total Posts : 11
  • Scores: 0
  • Reward points : 0
  • Joined: 11/28/2011
  • Status: offline
Signing a string Sunday, January 08, 2012 4:53 AM (permalink)
0
Hi
Can anyone please show me an example how to sign a string?
I need to Calculate an RFC 2104-compliant HMAC from a string with a private key using  the HmacSHA256  as the hash algorithm and then Convert the resulting value to base64.
i mannaged to create an object  or two but i don't knew how to take from there on.
here is an example of the object i created:
 
'dim myhash as new System.Security.Cryptography.HMACSHA256set
myhash = createobject("System.Security.Cryptography.HMACSHA256")WScript.echo myhash.Hashsize()WScript.echo myhash.key()
and here is another object i created:
set pkey = CreateObject("Chilkat.PrivateKey")
 
but as told before i need help to take it from here on
 

Thanks in advance.
<message edited by WeBeScript on Sunday, January 08, 2012 5:18 AM>
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Signing a string Monday, January 09, 2012 12:24 AM (permalink)
    5
    The hash function expects both key and data as byte arrays, so you need to convert your data from String to Byte() first. Try this:
    key = "..."
    str = "..."
    
    Set text = CreateObject("System.Text.UTF8Encoding")
    Set sha256 = CreateObject("System.Security.Cryptography.HMACSHA256")
    
    sha256.Key = text.GetBytes_4(key)
    hmac = sha256.ComputeHash_2(text.GetBytes_4(str))
    For the base64 encoding I'd suggest to modify Antonin Foller's Base64Encode() function, so that it will work with binary strings instead of normal strings (by replacing the string functions that operate on inData with their binary equivalents, i.e. Asc -> AscB, Mid -> MidB, ...).
     
    #2
      WeBeScript

      • Total Posts : 11
      • Scores: 0
      • Reward points : 0
      • Joined: 11/28/2011
      • Status: offline
      Re:Signing a string Monday, January 09, 2012 6:52 AM (permalink)
      0
      Thank you 59cobalt for your help
      i'll let you knew after i'll tryit
       
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9