Monday, 6 March 2017

PowerShell Encryption and Decryption, PS V 2.0 or Higher, Easy

Hi All, here's an easy example on how to encrypt or decrypt a string
this way IS NOT SURE because Key value is inside the *.ps1 file,
Another user can easily retrive your data.
This is only to understand basic of encryption in PowerShell



<#
LWEBCODE 
EASY POWERSHELL 2.0 or higher Encryption and Decryption
#>
$global:byteArr = New-Object Byte[] 32
$global:byteArr = [Byte[]](100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101, 100, 101)

function encrypt($content)
{
    $Password = $content | ConvertTo-SecureString -AsPlainText -Force
    $Password | ConvertFrom-SecureString -key $global:byteArr
    Write-Output "$Password"
    Write-Output "ENC END"
}

function decrypt($content)
{
    $User = "MyUserName"
    $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, ($content | ConvertTo-SecureString -Key $global:byteArr)
    $plainText = $MyCredential.GetNetworkCredential().Password

    Write-Output "Plain text: $plainText"
    Write-Output "DEC END"
}

encrypt("lwebcode is the best ;D ")

decrypt("76492d1116743f0423413b16050a5345MgB8AEoATwB4ADYAegBQAHcAaABhAGMATQBxAEwAWAA4AEI
ARgA2AE4ARwBlAFEAPQA9AHwAOQBjAGUAOABkAGQAYgAxADgAOABlAGMAMwA3AGEAYwA3AGQAMgA5AD
YAMgBmADQAZAA3ADIAYgAyADYANABiAGMAYQBjADIAMgA3AGEAYwA4AGQAYQBkAGUAOAAwADgANwAyA
DMANAAwADkAZQBhADcANgA5ADUANABhAGEAZgAwAGEAYwA3ADIANAA2ADcANQA3AGIAYQA4ADIAYgAx
ADUAOAAyADIANwBjADgAYgAxADgANAAyAGMAOAA5ADUAMQA0AGYAMQAxADgAOQAwADQAOQBiADQAZQA
yADMANwAyADgAZgBjAGMAOABkADkAYwAxAGMAMQBhADgANAA4AA==")

1 comment: