https://github.com/lowleveldesign/powercrypto
PowerShell module with various commands to encode/encrypt/print byte arrays.
https://github.com/lowleveldesign/powercrypto
cryptography powershell
Last synced: 8 months ago
JSON representation
PowerShell module with various commands to encode/encrypt/print byte arrays.
- Host: GitHub
- URL: https://github.com/lowleveldesign/powercrypto
- Owner: lowleveldesign
- License: mit
- Created: 2017-10-13T20:25:31.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-15T15:15:24.000Z (over 8 years ago)
- Last Synced: 2025-04-06T22:35:42.521Z (12 months ago)
- Topics: cryptography, powershell
- Language: PowerShell
- Size: 723 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Introduction
PowerShell module with various commands to encode/encrypt/print byte arrays.
Cryptographic commands are using implementations from **[the BouncyCastle library](http://bouncycastle.org/csharp/index.html)**. Consider [donating](https://www.bouncycastle.org/donate/index.cgi) them if you like this module.
## Available Commands
#### `Measure-HammingDistance`
Counts Hamming distance between bytes in arrays.
#### `Format-HexPrettyPrint`
Nicely prints a byte array. Example:
```
> Get-Content -Encoding Byte C:\Windows\notepad.exe -TotalCount 96 | Format-HexPrettyPrint
0 1 2 3 4 5 6 7 8 9 A B C D E F
0000: 4d 5a 90 00 03 00 00 00 04 00 00 00 ff ff 00 00 MZ..............
0010: b8 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 ........@.......
0020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0030: 00 00 00 00 00 00 00 00 00 00 00 00 f0 00 00 00 ................
0040: 0e 1f ba 0e 00 b4 09 cd 21 b8 01 4c cd 21 54 68 ........!..L.!Th
0050: 69 73 20 70 72 6f 67 72 61 6d 20 63 61 6e 6e 6f is program canno
```
#### `Get-RandomBytes`
Generates a byte array of randomly (cryptographically secure) generated bytes. Example:
```
PS> Get-RandomBytes -Length 10
25
192
252
150
203
166
195
174
190
222
```
#### `ConvertTo-Base64String`
Converts the byte array to the base64 encoded string. Example:
```
PS> Get-RandomBytes -Length 10 | ConvertTo-Base64String
LmIN1S5BGcu7RA==
```
#### `ConvertFrom-Base64String`
Converts the base64 encoded string to the byte array.
#### `ConvertTo-HexString`
Converts a byte array to its HEX representation. Example:
```
PS> Get-RandomBytes -Length 10 | ConvertTo-HexString
2d12ba68d2aaa3da9738
```
#### `ConvertFrom-HexString`
Converts a HEX string to a byte array.
#### `ConvertTo-ByteArray`
Converts string to a byte array using a specified encoding.
#### `ConvertFrom-ByteArray`
Converts a byte array to a string using a specified encoding.
#### `Protect-BinaryMessage`
Encrypts the provided message using a symmetric cipher.
#### `Unprotect-BinaryMessage`
Decrypts the provided cipher text using a symmetric cipher.
#### `Get-MessageDigest`
Calculates a message digests and outputs it as a byte array. Example:
```
PS> $b = ConvertTo-ByteArray "test message"
PS> Get-MessageDigest -Digest SHA256 $b | ConvertTo-HexString
3f0a377ba0a4a460ecb616f6507ce0d8cfa3e704025d4fda3ed0c5ca05468728
```
#### `Get-Mac`
Calculates a message MAC and outputs it as a byte array.
```
PS> $key = ConvertTo-ByteArray "YELLOW SUBMARINE"
PS> $b = ConvertTo-ByteArray "test message"
PS> Get-Mac -Key $key -BinaryMessage $b | ConvertTo-HexString
cfd4afbd065cacae3b33a848a9ce716e2d43eb06
```