Below is a snippet I used to sign files with md5hmac, may be of some use.
(I envy people easily reading other's J, I have difficulties reading mine a
while later )
regards,
Danil
qthash =: 4 : 0 NB. taken from qt ide, x is hash
algo name str, y is a data string, result is hex string of hash
c=.'"',libjqt,'" gethash ',(IFWIN#'+'),' i *c *c i * *i'
'r t m w p n'=. c cd (tolower x);y;(#y);(,2);,0
res=. memr p,0,n
if. r do. res (13!:8) 3 end.
res
)
bfh=:a.{~_2(16&#.)\'0123456789abcdef'i.] NB. bytes from hex string
(lowercase) (253*254)-:bfh 'fefc'
md5b=: [:bfh 'md5'&qthash NB. libjqt returns hex string as a
hash - convert it to bytes
hmac =: 1 : 0 NB. m is a key data, return verb
computing md5-based signature for y
if. 64<#m do. k=.md5b m else.k=.m end. NB. if m is longer than pad
(64 - block of md5) use md5 hash as a key
kb=.64{.a.i.k NB. extend to 64 the key pad data
with zero bytes
'i o'=.a.{~16b36 16b5c (22 b.)"0 1 kb NB. compute input and output
pads from the key bytes
md5b o, md5b i,y NB. calculate the final signature as in
wikipedia
)
md5SgnDir =: 3 : 0 NB. sign like CryproSign.jar: md5SgnDir
(<;._1)' ../sandbox *.cdr .md5 ../z/sssti_m7ium1_2016-05-25/crypto/key.txt'
'dr ms ex kf'=. y NB. directory name, mask of the filename,
extension added to md5 sign file, key file name
mk=.(fread kf)hmac NB. load a keyfile into a verb for
computing signature
((mk@:fread"0)fwrite"1 0(,&ex&.>"0))dr fdls ms NB. calculate the
signature of the content of each file and write to extended name
)
2017-12-22 4:32 GMT+03:00 bill lam <[email protected]>:
> if possible, please provide some examples or tests and I will add them to
> addons. Thanks
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm