salt.modules.hashutil

A collection of hashing and encoding functions

salt.modules.hashutil.base64_b64decode(instr)

Decode a base64-encoded string using the "modern" Python interface

2016.3.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.base64_b64decode 'Z2V0IHNhbHRlZA=='
salt.modules.hashutil.base64_b64encode(instr)

Encode a string as base64 using the "modern" Python interface.

Among other possible differences, the "modern" encoder does not include newline ('n') characters in the encoded output.

2016.3.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.base64_b64encode 'get salted'
salt.modules.hashutil.base64_decodefile(instr, outfile)

Decode a base64-encoded string and write the result to a file

2015.2.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.base64_decodefile instr='Z2V0IHNhbHRlZAo=' outfile='/path/to/binary_file'
salt.modules.hashutil.base64_decodestring(instr)

Decode a base64-encoded string using the "legacy" Python interface

2014.7.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.base64_decodestring instr='Z2V0IHNhbHRlZAo='
salt.modules.hashutil.base64_encodefile(fname)

Read a file from the file system and return as a base64 encoded string

2016.3.0 新版功能.

Pillar example:

path:
  to:
    data: |
      {{ salt.hashutil.base64_encodefile('/path/to/binary_file') | indent(6) }}

The file.decode state function can be used to decode this data and write it to disk.

命令行接口CLI 范例:

salt '*' hashutil.base64_encodefile /path/to/binary_file
salt.modules.hashutil.base64_encodestring(instr)

Encode a string as base64 using the "legacy" Python interface.

Among other possible differences, the "legacy" encoder includes a newline ('n') character after every 76 characters and always at the end of the encoded string.

2014.7.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.base64_encodestring 'get salted'
salt.modules.hashutil.digest(instr, checksum='md5')

Return a checksum digest for a string

instr
A string
checksum : md5
The hashing algorithm to use to generate checksums. Valid options: md5, sha256, sha512.

命令行接口CLI 范例:

salt '*' hashutil.digest 'get salted'
salt.modules.hashutil.digest_file(infile, checksum='md5')

Return a checksum digest for a file

infile
A file path
checksum : md5
The hashing algorithm to use to generate checksums. Wraps the hashutil.digest execution function.

命令行接口CLI 范例:

salt '*' hashutil.digest_file /path/to/file
salt.modules.hashutil.hmac_signature(string, shared_secret, challenge_hmac)

Verify a challenging hmac signature against a string / shared-secret

2014.7.0 新版功能.

Returns a boolean if the verification succeeded or failed.

命令行接口CLI 范例:

salt '*' hashutil.hmac_signature 'get salted' 'shared secret' 'eBWf9bstXg+NiP5AOwppB5HMvZiYMPzEM9W5YMm/AmQ='
salt.modules.hashutil.md5_digest(instr)

Generate an md5 hash of a given string

2014.7.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.md5_digest 'get salted'
salt.modules.hashutil.sha256_digest(instr)

Generate an sha256 hash of a given string

2014.7.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.sha256_digest 'get salted'
salt.modules.hashutil.sha512_digest(instr)

Generate an sha512 hash of a given string

2014.7.0 新版功能.

命令行接口CLI 范例:

salt '*' hashutil.sha512_digest 'get salted'