up
Hmac
Available algorithm
| command: | ns_mhash hmac algorithms |
| result: | list of available hmac hash algorithms |
| example: | [ns_mhash hmac algorithms]=<%=[ns_mhash hmac algorithms]%> |
create new hmac HASH object
| command: | ns_mhash hmac new algorithm_name password |
| parameters: | algorithm_name - name of hash algorithm: MD5, SHA1, ...
password - hmac password
|
| result: | hmac HASH object using in other commands |
| example: | [ns_mhash hmac new MD5 foobar] |
destroy hmac HASH object
| command: | ns_mhash hmac destroy hash_id |
| parameters: | hash_id - id of hmac HASH object generated by new command (above) |
| result: | destroy HASH object without any output |
| example: | ns_mhash hmac destroy $hashid |
end/print hmac HASH object
| command: | ns_mhash hmac end ?-bin|-base64? hash_id |
| parameters: |
hash_id - id of hmac HASH object generated by new command (above)
?-bin|-base64? - type of output format for generated hmac hash string :: default: hexadecimal string; binary (TclByteArray): -bin; binary base64 encoded: -base64
|
| result: | return output hmac hash string and destroy hmac HASH object |
| example: | set out [ns_mhash hmac end -base64 $hashid] |
copy hmac HASH object
| command: | ns_mhash hmac copy hash_id |
| parameters: | hash_id - id of hmac HASH object generated by new command (above) |
| result: | copy of hmac HASH object |
| example: | set hashid2 [ns_mhash hmac copy $hashid] |
update hmac HASH object
| command: | ns_mhash hmac update hash_id string |
| parameters: | hash_id - id of hmac HASH object generated by new command (above)
string - string you want to hash |
| result: | update hmac HASH object by string. You can use this repeatedly |
| example: | ns_mhash hmac update $hashid "Hello world" |
detach hmac HASH object
| command: | ns_mhash hmac detach hash_id |
| parameters: | hash_id - id of hmac HASH object generated by new command (above) |
| result: | detach hmac HASH object from Tcl interpreter. You can you with nsv_* for share hmac HASH object. |
| example: |
set detachid [ns_mhash hmac detach $hashid]
nsv_set test test $detachid
|
attach hmac HASH object
| command: | ns_mhash hmac attach detach_hash_id |
| parameters: | detach_hash_id - detach id of hmac HASH object generated by detach command (above) |
| result: | attach hmac HASH object to Tcl interpreter for next using. You can you with nsv_* for share hmac HASH object. |
| example: |
set detachid [nsv_get test test]
set hashid [ns_mhash hmac attach $detachid]
|
Full samples:
simple without output
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello world"
ns_mhash hmac destroy $td
simple with hash string (base64)
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello world"
set out [ns_mhash hmac end -base64 $td]
ns_adp_puts $out
result: <%
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello world"
set out [ns_mhash hmac end -base64 $td]
ns_adp_puts $out
%>
simple with hash string (hexadecimal)
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello world"
set out [ns_mhash hmac end $td]
ns_adp_puts $out
result: <%
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello world"
set out [ns_mhash hmac end $td]
ns_adp_puts $out
%>
copy of HASH object
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello"
set td2 [ns_mhash hmac copy $td]
set out [ns_mhash hmac end $td]
ns_mhash hmac update $td2 " "
ns_mhash hmac update $td2 "world"
set out2 [ns_mhash hmac end $td2]
ns_adp_puts $out
ns_adp_puts $out2
<%
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello"
set td2 [ns_mhash hmac copy $td]
set out [ns_mhash hmac end $td]
ns_mhash hmac update $td2 " "
ns_mhash hmac update $td2 "world"
set out2 [ns_mhash hmac end $td2]
%>
result out: <%=$out%>
result out2: <%=${out2}%>
attach/detach of HASH object
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello"
set detachid [ns_mhash hmac detach $td]
nsv_set test test $detachid
set detachid [nsv_get test test]
set td [ns_mhash hmac attach $detachid]
ns_mhash hmac update $td " "
ns_mhash hmac update $td "world"
set out [ns_mhash hmac end $td]
ns_adp_puts $out
<%
set td [ns_mhash hmac new SHA1 foobar]
ns_mhash hmac update $td "Hello"
set detachid [ns_mhash hmac detach $td]
nsv_set test test $detachid
set detachid [nsv_get test test]
set td [ns_mhash hmac attach $detachid]
ns_mhash hmac update $td " "
ns_mhash hmac update $td "world"
set out [ns_mhash hmac end $td]
%>
result: <%=$out%>