Created
November 7, 2017 16:26
-
-
Save Luiz-Monad/9574a4503c6fbcc1c9ebab85a1cd176c to your computer and use it in GitHub Desktop.
cold storage crypto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function encrypt ([securestring] $pass) { | |
$key = (2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43,6,6,6,6,6,6,31,33,60,23) | |
$securepass = $pass | ConvertFrom-SecureString -Key $key | |
$bytes = [byte[]][char[]]$securepass | |
$csp = New-Object System.Security.Cryptography.CspParameters | |
$csp.KeyContainerName = 'SuperSecretProcessOnMachine' | |
$csp.Flags = $csp.Flags -bor [System.Security.Cryptography.CspProviderFlags]::UseMachineKeyStore | |
$rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider -ArgumentList 5120,$csp | |
$rsa.PersistKeyInCsp = $true | |
$encrypted = $rsa.Encrypt($bytes,$true) | |
$encrypted -join ',' | |
} | |
function decrypt ([string] $securepass) { | |
$key = (2,3,56,34,254,222,1,1,2,23,42,54,33,233,1,34,2,7,6,5,35,43,6,6,6,6,6,6,31,33,60,23) | |
$csp = New-Object System.Security.Cryptography.CspParameters | |
$csp.KeyContainerName = 'SuperSecretProcessOnMachine' | |
$csp.Flags = $csp.Flags -bor [System.Security.Cryptography.CspProviderFlags]::UseMachineKeyStore | |
$rsa = New-Object System.Security.Cryptography.RSACryptoServiceProvider -ArgumentList 5120,$csp | |
$rsa.PersistKeyInCsp = $true | |
$encrypted = $securepass -split ',' | |
$password = [char[]]$rsa.Decrypt($encrypted, $true) -join '' | ConvertTo-SecureString -Key $key | |
New-Object System.Management.Automation.PsCredential ( 'tome', $password ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment