File: hash-string.2gg

package info (click to toggle)
golf 601.4.41-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,824 kB
  • sloc: ansic: 20,020; sh: 1,171; makefile: 292
file content (77 lines) | stat: -rw-r--r-- 1,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
.TH GOLF 2gg $VERSION $DATE Development Tools
.SH NAME
hash-string \-  (encryption)
.SH PURPOSE
Hash a string.

.SH SYNTAX

.RS 4
.EX

hash-string <string> to <result> \\
    [ binary [ <binary> ] \\
    [ digest <digest algorithm> ]

.EE
.RE

.SH DESCRIPTION
hash-string produces by default a SHA256 hash of <string> (if "digest" clause is not used), and stores the result into <result>. You can use a different <digest algorithm> in "digest" clause (for example "SHA3-256"). To see a list of available digests:

.RS 4
.EX

\[char35]get digests
openssl list -digest-algorithms

.EE
.RE

If "binary" clause is used without boolean variable <binary>, or if <binary> evaluates to true, then the <result> is a binary string that may contain null-characters. With the default SHA256, it is 32 bytes in length, while for instance with SHA3-384 it is 48 bytes in length, etc. 

Without "binary" clause, or if <binary> evaluates to false, each binary byte of hashed string is converted to two hexadecimal characters ("0"-"9" and "a"-"f"), hence <result> is twice as long as with "binary" clause. 

.SH EXAMPLES
String "result" will have a hashed value of the given string, an example of which might look like "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":

.RS 4
.EX

hash-string "hello world" to hash

.EE
.RE

Using a different digest:

.RS 4
.EX

hash-string "hello world" to hash digest "sha3-384"

.EE
.RE

Producing a binary value instead of a null-terminated hexadecimal string:

.RS 4
.EX

hash-string "hello world" to hash digest "sha3-384" binary 

.EE
.RE

.SH SEE ALSO
 Encryption

\fBdecrypt-data\fP  
\fBderive-key\fP  
\fBencrypt-data\fP  
\fBhash-string\fP  
\fBhmac-string\fP  
\fBrandom-crypto\fP  
\fBrandom-string\fP   
See all 
\fBdocumentation\fP