Update README.md

This commit is contained in:
freedbygrace
2023-10-21 22:11:22 -04:00
committed by GitHub
parent 30573db01f
commit b0b30da6b1
+297 -99
View File
@@ -1,129 +1,327 @@
# Invoke-SymmectricCryptography # Invoke-SymmectricCryptography
## SYNOPSIS
Performs value encryption or decryption using a specified algorithm. Performs value encryption or decryption using a specified algorithm.
.SYNOPSIS ## SYNTAX
Performs value encryption or decryption using a specified algorithm.
.DESCRIPTION
A random key and initialization vector (IV) will be generated with each execution for maximum security.
This means that the resulting encrypted data will NEVER be the same, even if the value to be encrypted is!
This function is great for encrypting data that will NOT be transmitted over a network. In other words, data at rest.
If transmitting the data over a network is required, consider breaking the encrypted data, key, and initialization vector apart. ### Encryption (Default)
```
.PARAMETER Encrypt Invoke-SymmectricCryptography [-Encrypt] -Algorithm <String> -Data <String[]> [-Export]
Specifies that encryption will be performed. [-ExportFormat <String>] [-ExportPath <FileInfo>] [-ContinueOnError] [<CommonParameters>]
```
.PARAMETER Decrypt ### Decryption
Specifies that decryption will be performed. ```
Invoke-SymmectricCryptography [-Decrypt] -Algorithm <String> -EncryptedData <String> -Key <String>
-InitializationVector <String> [-ContinueOnError] [<CommonParameters>]
```
.PARAMETER Algorithm ## DESCRIPTION
Specifies the algorithm used for encryption or decryption. A random key and initialization vector (IV) will be generated with each execution for maximum security.
.PARAMETER Data This means that the resulting encrypted data will NEVER be the same, even if the value to be encrypted is!
Specifies the original string value that will be encrypted.
.PARAMETER EncryptedData This function is great for encrypting data that will NOT be transmitted over a network.
Specifies the previously encrypted string value that will be decrypted. In other words, data at rest.
.PARAMETER Key If transmitting the data over a network is required, consider breaking the encrypted data, key, and initialization vector apart.
Specifies the decryption key that is required for decryption.
.PARAMETER InitializationVector ## EXAMPLES
Specifies the initialization vector (IV) that is required for decryption.
.PARAMETER Export ### EXAMPLE 1
Specifies that the encrypted data is to be exported. ```
$EncryptionResult = Invoke-SymmectricCryptography -Encrypt -Algorithm AES -Data 'SomeValueRequiringEncryption'
.PARAMETER ExportFormat Write-Output -InputObject ($EncryptionResult)
Specifies the format that the encrypted data will be exported in. ```
### EXAMPLE 2
```
$DecryptionResult = Invoke-SymmectricCryptography -Decrypt -Algorithm AES -Data 'msDFP5hUQo8flkb+qnRSl+1yEaKEhl5Lr3LBfClXSMY=' -Key 'oc5cuCuOhw1qJvwr1iwHr9mOWXmLTMCgw1zlIOZDf78=' -InitializationVector 'zDpcPE2a4YWF/gFmGQoZhQ=='
.PARAMETER ExportPath Write-Output -InputObject ($DecryptionResult)
Specifies the path that the encrypted data will be exported to. ```
### EXAMPLE 3
```
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
.PARAMETER ContinueOnError $InvokeSymmectricCryptographyParameters.Encrypt = $True
Specifies that errors will be logged as warnings, but not considered fatal. $InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.Data = New-Object -TypeName 'System.Collections.Generic.List\[System.String\]'
.EXAMPLE $InvokeSymmectricCryptographyParameters.Data.Add("AValueThatNeedsToBeEncrypted")
$EncryptionResult = Invoke-SymmectricCryptography -Encrypt -Algorithm AES -Data 'SomeValueRequiringEncryption' $InvokeSymmectricCryptographyParameters.Data.Add("AnotherValueThatNeedsToBeEncrypted")
$InvokeSymmectricCryptographyParameters.Export = $True
$InvokeSymmectricCryptographyParameters.ExportFormat = 'XML'
$InvokeSymmectricCryptographyParameters.ExportPath = "$($Env:UserProfile)\Downloads\EncryptedData.xml"
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
Write-Output -InputObject ($EncryptionResult) $EncryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters
.EXAMPLE Write-Output -InputObject ($EncryptionResult)
$DecryptionResult = Invoke-SymmectricCryptography -Decrypt -Algorithm AES -Data 'msDFP5hUQo8flkb+qnRSl+1yEaKEhl5Lr3LBfClXSMY=' -Key 'oc5cuCuOhw1qJvwr1iwHr9mOWXmLTMCgw1zlIOZDf78=' -InitializationVector 'zDpcPE2a4YWF/gFmGQoZhQ==' ```
### EXAMPLE 4
```
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
Write-Output -InputObject ($DecryptionResult) $InvokeSymmectricCryptographyParameters.Decrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.EncryptedData = 'msDFP5hUQo8flkb+qnRSl+1yEaKEhl5Lr3LBfClXSMY='
$InvokeSymmectricCryptographyParameters.Key = 'oc5cuCuOhw1qJvwr1iwHr9mOWXmLTMCgw1zlIOZDf78='
$InvokeSymmectricCryptographyParameters.InitializationVector = 'zDpcPE2a4YWF/gFmGQoZhQ=='
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
.EXAMPLE $DecryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$InvokeSymmectricCryptographyParameters.Encrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.Data = New-Object -TypeName 'System.Collections.Generic.List[System.String]'
$InvokeSymmectricCryptographyParameters.Data.Add("AValueThatNeedsToBeEncrypted")
$InvokeSymmectricCryptographyParameters.Data.Add("AnotherValueThatNeedsToBeEncrypted")
$InvokeSymmectricCryptographyParameters.Export = $True
$InvokeSymmectricCryptographyParameters.ExportFormat = 'XML'
$InvokeSymmectricCryptographyParameters.ExportPath = "$($Env:UserProfile)\Downloads\EncryptedData.xml"
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
$EncryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters Write-Output -InputObject ($DecryptionResult)
```
### EXAMPLE 5
```
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
Write-Output -InputObject ($EncryptionResult) $InvokeSymmectricCryptographyParameters.Encrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.Data = "AValueThatNeedsToBeEncrypted"
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
.EXAMPLE $EncryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$InvokeSymmectricCryptographyParameters.Decrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.EncryptedData = 'msDFP5hUQo8flkb+qnRSl+1yEaKEhl5Lr3LBfClXSMY='
$InvokeSymmectricCryptographyParameters.Key = 'oc5cuCuOhw1qJvwr1iwHr9mOWXmLTMCgw1zlIOZDf78='
$InvokeSymmectricCryptographyParameters.InitializationVector = 'zDpcPE2a4YWF/gFmGQoZhQ=='
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
$DecryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters Write-Output -InputObject ($EncryptionResult)
Write-Output -InputObject ($DecryptionResult) $InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$InvokeSymmectricCryptographyParameters.Decrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = $EncryptionResult.Algorithm
$InvokeSymmectricCryptographyParameters.EncryptedData = $EncryptionResult.Data
$InvokeSymmectricCryptographyParameters.Key = $EncryptionResult.Key
$InvokeSymmectricCryptographyParameters.InitializationVector = $EncryptionResult.InitializationVector
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
.EXAMPLE $DecryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$InvokeSymmectricCryptographyParameters.Encrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = 'AES'
$InvokeSymmectricCryptographyParameters.Data = "AValueThatNeedsToBeEncrypted"
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
$EncryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters Write-Output -InputObject ($DecryptionResult)
```
## PARAMETERS
Write-Output -InputObject ($EncryptionResult) ### -Algorithm
Specifies the algorithm used for encryption or decryption.
$InvokeSymmectricCryptographyParameters = New-Object -TypeName 'System.Collections.Specialized.OrderedDictionary'
$InvokeSymmectricCryptographyParameters.Decrypt = $True
$InvokeSymmectricCryptographyParameters.Algorithm = $EncryptionResult.Algorithm
$InvokeSymmectricCryptographyParameters.EncryptedData = $EncryptionResult.Data
$InvokeSymmectricCryptographyParameters.Key = $EncryptionResult.Key
$InvokeSymmectricCryptographyParameters.InitializationVector = $EncryptionResult.InitializationVector
$InvokeSymmectricCryptographyParameters.ContinueOnError = $False
$InvokeSymmectricCryptographyParameters.Verbose = $True
$DecryptionResult = Invoke-SymmectricCryptography @InvokeSymmectricCryptographyParameters ```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Write-Output -InputObject ($DecryptionResult) Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
.NOTES ### -ContinueOnError
Any useful tidbits Specifies that errors will be logged as warnings, but not considered fatal.
.LINK ```yaml
https://codeandkeep.com/PowerShell-Aes-Encryption/ Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
.LINK Aliases:
https://smsagent.blog/2022/09/23/encrypting-sensitive-data-for-transit-or-rest-with-powershell/
Required: False
.LINK Position: Named
https://stackoverflow.com/questions/67883498/powershell-password-encryption-decryption-with-key Default value: False
Accept pipeline input: False
.LINK Accept wildcard characters: False
https://medium.com/@sumindaniro/encrypt-decrypt-data-with-powershell-4a1316a0834b ```
### -Data
Specifies the original string value that will be encrypted.
```yaml
Type: System.String[]
Parameter Sets: Encryption
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Decrypt
Specifies that decryption will be performed.
```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: Decryption
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -Encrypt
Specifies that encryption will be performed.
```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: Encryption
Aliases:
Required: True
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -EncryptedData
Specifies the previously encrypted string value that will be decrypted.
```yaml
Type: System.String
Parameter Sets: Decryption
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Export
Specifies that the encrypted data is to be exported.
```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: Encryption
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```
### -ExportFormat
Specifies the format that the encrypted data will be exported in.
```yaml
Type: System.String
Parameter Sets: Encryption
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -ExportPath
Specifies the path that the encrypted data will be exported to.
```yaml
Type: System.IO.FileInfo
Parameter Sets: Encryption
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -InitializationVector
Specifies the initialization vector (IV) that is required for decryption.
```yaml
Type: System.String
Parameter Sets: Decryption
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Key
Specifies the decryption key that is required for decryption.
```yaml
Type: System.String
Parameter Sets: Decryption
Aliases:
Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
### System.Management.Automation.PSObject[]
## NOTES
Any useful tidbits
## RELATED LINKS
[https://codeandkeep.com/PowerShell-Aes-Encryption/](https://codeandkeep.com/PowerShell-Aes-Encryption/)
[https://smsagent.blog/2022/09/23/encrypting-sensitive-data-for-transit-or-rest-with-powershell/](https://smsagent.blog/2022/09/23/encrypting-sensitive-data-for-transit-or-rest-with-powershell/)
[https://stackoverflow.com/questions/67883498/powershell-password-encryption-decryption-with-key](https://stackoverflow.com/questions/67883498/powershell-password-encryption-decryption-with-key)
[https://medium.com/@sumindaniro/encrypt-decrypt-data-with-powershell-4a1316a0834b](https://medium.com/@sumindaniro/encrypt-decrypt-data-with-powershell-4a1316a0834b)
## SAMPLE OUTPUT:
```
Algorithm : AES
CryptoServiceProvider : System.Security.Cryptography.AESCryptoServiceProvider
CryptoServiceProviderName : AESCryptoServiceProvider
EncryptedDataObjectList : {@{Algorithm=AES; EncryptedData=IGHYeiv2xgIx5bk3JtZvvgsex2p4KV3TL4GGDs9jfzY=; Key=Jpt2nyeCOfxDZb2UuzM92DCrBAhLiv1gXoASo2zOfL4=;
InitializationVector=SOpUqOH6CRvhtF40eM8Cng==;
DKIV=IGHYeiv2xgIx5bk3JtZvvgsex2p4KV3TL4GGDs9jfzY=:Jpt2nyeCOfxDZb2UuzM92DCrBAhLiv1gXoASo2zOfL4=:SOpUqOH6CRvhtF40eM8Cng==}, @{Algorithm=AES;
EncryptedData=gulf1oID8ueF0SgrziYCF8VDHmKNJUCg+CgolgVHE2acMvFQYL26OvaSww83lxSI; Key=3LZn9vQWAonvhSSavNectgiBex9goOFI/Nq6Wht16ao=;
InitializationVector=SkQewVlEyy5Qp1O6yOWH9A==;
DKIV=gulf1oID8ueF0SgrziYCF8VDHmKNJUCg+CgolgVHE2acMvFQYL26OvaSww83lxSI:3LZn9vQWAonvhSSavNectgiBex9goOFI/Nq6Wht16ao=:SkQewVlEyy5Qp1O6yOWH9A==}}
ExportFormat : XML
ExportContent : <?xml version="1.0" encoding="utf-8"?>
<Settings>
<Metadata>
<GeneratedDate>2023-10-21T22:10:44</GeneratedDate>
</Metadata>
<Secrets Algorithm="AES">
<Secret Enabled="True" ID="59A61758-4C3F-470F-9900-F7BF7A2CDAED">
<EncryptedData><![CDATA[IGHYeiv2xgIx5bk3JtZvvgsex2p4KV3TL4GGDs9jfzY=]]></EncryptedData>
<Key><![CDATA[Jpt2nyeCOfxDZb2UuzM92DCrBAhLiv1gXoASo2zOfL4=]]></Key>
<InitializationVector><![CDATA[SOpUqOH6CRvhtF40eM8Cng==]]></InitializationVector>
</Secret>
<Secret Enabled="True" ID="2E4263AF-84C7-4248-A42F-E81A584BD3AD">
<EncryptedData><![CDATA[gulf1oID8ueF0SgrziYCF8VDHmKNJUCg+CgolgVHE2acMvFQYL26OvaSww83lxSI]]></EncryptedData>
<Key><![CDATA[3LZn9vQWAonvhSSavNectgiBex9goOFI/Nq6Wht16ao=]]></Key>
<InitializationVector><![CDATA[SkQewVlEyy5Qp1O6yOWH9A==]]></InitializationVector>
</Secret>
</Secrets>
</Settings>
ExportPath : C:\Users\alpha\Downloads\EncryptedData.xml
```