Encoding & Hashing
Encoding & Hashing
Section titled “Encoding & Hashing”base64, md5sum, sha1sum, sha256sum, and file for encoding, integrity checking, and file type detection.
base64
Section titled “base64”Encode or decode data in Base64 format.
base64 [OPTIONS] [FILE]| Flag | Description |
|---|---|
-d, --decode | Decode Base64 input back to original data |
-w NUM, --wrap=NUM | Wrap encoded output at NUM columns (default: 76, 0 = no wrap) |
Return Type
Section titled “Return Type”Returns a PsBash.TextOutput object with the encoded or decoded string as BashText.
Examples
Section titled “Examples”Encode a string from the pipeline:
echo 'hello' | base64aGVsbG8KDecode a Base64 string:
echo 'aGVsbG8K' | base64 -dhelloEncode a file:
base64 image.pngEncode without line wrapping:
echo 'a longer string that would normally wrap' | base64 -w 0Decode a Base64 file:
base64 -d encoded.txtmd5sum
Section titled “md5sum”Compute MD5 message digest for files or pipeline input.
md5sum [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-c, --check | Read checksums from file and verify them |
-b, --binary | Read files in binary mode |
TextOutput Properties
Section titled “TextOutput Properties”Each result is a PsBash.TextOutput object:
| Property | Type | Description |
|---|---|---|
Hash | string | Hex-encoded MD5 digest |
FileName | string | Path to the hashed file, or - for pipeline input |
Algorithm | string | MD5 |
BashText | string | Formatted hash filename output |
Examples
Section titled “Examples”Hash a file:
md5sum README.mdd41d8cd98f00b204e9800998ecf8427e README.mdHash multiple files:
md5sum file1.txt file2.txt098f6bcd4621d373cade4e832627b4f6 file1.txtad0234829205b9033196ba818f7a872b file2.txtHash pipeline input:
echo 'data' | md5sum8d777f385d3dfec8815d20f7496026dc -Access the hash property directly:
$result = md5sum README.md$result.Hash # "d41d8cd98f00b204e9800998ecf8427e"$result.Algorithm # "MD5"sha1sum
Section titled “sha1sum”Compute SHA-1 message digest for files or pipeline input. Same interface as md5sum.
sha1sum [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-c, --check | Read checksums from file and verify them |
-b, --binary | Read files in binary mode |
TextOutput Properties
Section titled “TextOutput Properties”Each result is a PsBash.TextOutput object:
| Property | Type | Description |
|---|---|---|
Hash | string | Hex-encoded SHA-1 digest |
FileName | string | Path to the hashed file, or - for pipeline input |
Algorithm | string | SHA1 |
BashText | string | Formatted hash filename output |
Examples
Section titled “Examples”Hash a file:
sha1sum README.mdda39a3ee5e6b4b0d3255bfef95601890afd80709 README.mdHash from pipeline:
echo 'data' | sha1suma17c9aaa61e80a1bf71d0d850af4e5baa9800bbd -Use the typed properties:
$result = sha1sum config.yml$result.Hash # hex digest string$result.FileName # "config.yml"sha256sum
Section titled “sha256sum”Compute SHA-256 message digest for files or pipeline input. Same interface as md5sum.
sha256sum [OPTIONS] [FILE...]| Flag | Description |
|---|---|
-c, --check | Read checksums from file and verify them |
-b, --binary | Read files in binary mode |
TextOutput Properties
Section titled “TextOutput Properties”Each result is a PsBash.TextOutput object:
| Property | Type | Description |
|---|---|---|
Hash | string | Hex-encoded SHA-256 digest |
FileName | string | Path to the hashed file, or - for pipeline input |
Algorithm | string | SHA256 |
BashText | string | Formatted hash filename output |
Examples
Section titled “Examples”Hash a file:
sha256sum README.mde3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 README.mdHash pipeline input:
echo 'data' | sha256sumb8e2f6eb2098b6d0fcbabf2db0b3b5e24bfe7b6eab9a573ae322e4f0a7c17e3c -Compare checksums programmatically:
$expected = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'$actual = (sha256sum README.md).Hash$expected -eq $actual # TrueDetermine the type of a file by inspecting its contents (magic bytes).
file [OPTIONS] FILE...| Flag | Description |
|---|---|
-b, --brief | Omit the filename prefix from output |
-i, --mime | Output MIME type instead of human-readable description |
-L, --dereference | Follow symbolic links (accepted for compatibility) |
Detected File Types
Section titled “Detected File Types”| Type | Magic Bytes | Description | MIME Type |
|---|---|---|---|
| PNG | 89 50 4E 47 | PNG image data | image/png |
| JPEG | FF D8 | JPEG image data | image/jpeg |
25 50 44 46 | PDF document | application/pdf | |
| ZIP | 50 4B 03 04 | Zip archive data | application/zip |
| ELF | 7F 45 4C 46 | ELF executable | application/x-executable |
| GIF | 47 49 46 38 | GIF image data | image/gif |
| RIFF | 52 49 46 46 | RIFF data | application/octet-stream |
| Text | (no binary bytes) | ASCII text | text/plain |
Files that match no magic signature and contain binary bytes are reported as data with MIME type application/octet-stream.
TextOutput Properties
Section titled “TextOutput Properties”Each result is a PsBash.TextOutput object:
| Property | Type | Description |
|---|---|---|
FileName | string | Path to the inspected file |
FileType | string | Human-readable type description |
MimeType | string | MIME type string |
BashText | string | Formatted output string |
Examples
Section titled “Examples”Detect file type:
file image.pngimage.png: PNG image dataBrief output (no filename):
file -b image.pngPNG image dataMIME type output:
file -i document.pdfdocument.pdf: application/pdfCombine brief and MIME:
file -bi archive.zipapplication/zipCheck multiple files:
file script.ps1 photo.jpg data.binscript.ps1: ASCII textphoto.jpg: JPEG image datadata.bin: dataAccess typed properties:
$info = file image.png$info.FileType # "PNG image data"$info.MimeType # "image/png"