Hashing with Iron and Flexible Streams

I am trying to use some lines in a general Lisp application that I am working on. The sd-sha1 package seems unsupported, and for some time it has been judging by the CLiki page, which suggests using Ironclad. Fair enough,

=> (require 'ironclad) NIL 

Ironclad does not execute string digests; this is indicated on the project page as an intentional design choice, what I have to do is convert my string to a byte string and a hash. In other words

 => (ironclad:digest-sequence :sha1 (flexi-streams:string-to-octets "Hello there")) #(114 108 118 85 62 26 63 222 162 145 52 243 110 106 242 234 5 236 92 206) 

Well, now the point is that the point of all this exercise is to pull the string of the sha1-hashed source string input, which means that I really want to convert the above back to string format. But,

 => (flexi-streams:octets-to-string (ironclad:digest-sequence :sha1 (flexi-streams:string-to-octets "Hello there")) :external-format :utf-8) This sequence can't be decoded using UTF-8 as it is too short. 1 octet missing at then end. [Condition of type FLEXI-STREAMS:EXTERNAL-FORMAT-ENCODING-ERROR] Restarts: 0: [ABORT] Exit debugger, returning to top level. 

Another option is to allow flexi-streams to output the correct encoding.

 => (flexi-streams:octets-to-string (ironclad:digest-sequence :sha1 (flexi-streams:string-to-octets "Hello there"))) "rlvU>?รžยข4รณnjรฒรชรฌ\\รŽ" 

What kind of work, but I feel that the result should not contain control characters. According to flexi threads, the default encoding is :latin , so I'm really not sure what to do at this point.

What am I doing wrong? How to get a string representation of a SHA1-rewritten string in Common Lisp?

In case that matters, I run SBCL (the version from apt-get, which in my opinion is 1.0.29) via Emacs + SLIME.

+7
common-lisp digest
source share
1 answer

The octets you get from ironclad:digest-sequence are the SHA1 digest. You need a string representing the hexadecimal encoding of these bytes. Ironclad acts as a built-in: ironclad:byte-array-to-hex-string .

+9
source share

All Articles