Function | Package: excl | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version

## sha512-final

Arguments: context &key return

Finalize and return the SHA512 hash from context in a format determined by the return keyword argument.

return can be one of the following values:

- `:integer` (the default): the return value is an integer of up to 128 bits representing the digest. Warning: note that an integer representation of the digest potentially loses information if the generated signature has leading octets containing only zeroes. Care should be taking when using this return type if you intend to further encode the signature (such as to a base64-encoded string). See the example below.
- :usb8: return an (unsigned-byte 8) array containing the digest.
- :hex: return a string containing the hexadecimal representation of the digest. See hex-string-to-integer.

    cl-user(4): (setq c (sha512-init))
    #S(excl::md-context :ctx 9184192 :size 64)
    cl-user(5): (sha512-update c "foo")
    cl-user(6): (sha512-final c :return :usb8)
    #(247 251 186 110 6 54 248 144 229 111 ...)

    ;;  Potential problem with :return :integer (or :return unspecified
    ;;  as the default is :integer). The call is to SHA512-FILE which calls
    ;;  SHA512-FINAL and returns the value SHA512-FINAL returns.
    ;;
    ;;  Here we get the sha512 value in a shell:
    % openssl dgst -sha512 -hex cmp04-profmenu.jpg
    SHA512(xmldoc/html101/pictures/cmp04-profmenu.jpg)= 083059e92e5cecc3bbcf1707bc0f167564f7981a03b5340b1d1755f84ef04b239929c56c3b08409d31188a8103e24daf1311f5f4d01cb55180b1a000d5edf58f

    ;; Now we get it with SHA512-FILE:
    cl-user(17): (sha512-file "~/cmp04-profmenu.jpg")
    428886023486142793197430632417588933862863719105103677963658399518713040127487056708272152409738347556264379546041790497093717768109375086135443767293327
    cl-user(18): (format t "~x" *)
    83059e92e5cecc3bbcf1707bc0f167564f7981a03b5340b1d1755f84ef04b239929c56c3b08409d31188a8103e24daf1311f5f4d01cb55180b1a000d5edf58f
    nil
    cl-user(19):

    ;; Note the hex values are the same but the leading 0 is not printed
    ;; by Lisp, which is dealing with the value as an integer. The leading
    ;; 0 is preserved when the :return is :hex:
    cl-user(21): (sha512-file "~/cmp04-profmenu.jpg" :return :hex)
    "083059e92e5cecc3bbcf1707bc0f167564f7981a03b5340b1d1755f84ef04b239929c56c3b08409d31188a8103e24daf1311f5f4d01cb55180b1a000d5edf58f"
    cl-user(22):

See MD*, SHA*, HMAC, and other message digest support in miscellaneous.htm. See also digest-final.

Copyright (c) 1998-2022, Franz Inc. Lafayette, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

|  | ToC | DocOverview | CGDoc | RelNotes | FAQ | Index | PermutedIndex
| Allegro CL version 10.1 Unrevised from 10.0 to 10.1. 10.0 version