Last active
December 15, 2020 20:52
-
-
Save FrankSpierings/a5af505068073feea0ae to your computer and use it in GitHub Desktop.
Powershell ECDiffieHellmanP256 Example
This file contains 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
[System.Security.Cryptography.CngKey]$aliceKey = [System.Security.Cryptography.CngKey]::Create([System.Security.Cryptography.CngAlgorithm]::ECDiffieHellmanP256) | |
[System.Security.Cryptography.CngKey]$bobKey = [System.Security.Cryptography.CngKey]::Create([System.Security.Cryptography.CngAlgorithm]::ECDiffieHellmanP256) | |
[Byte[]]$alicePubKeyBlob = $aliceKey.Export([System.Security.Cryptography.CngKeyBlobFormat]::EccPublicBlob) | |
[Byte[]]$bobPubKeyBlob = $bobKey.Export([System.Security.Cryptography.CngKeyBlobFormat]::EccPublicBlob) | |
[System.Security.Cryptography.ECDiffieHellmanCng]$aliceAlgorithm = New-Object System.Security.Cryptography.ECDiffieHellmanCng($aliceKey) | |
[System.Security.Cryptography.CngKey]$bobPubKey = [System.Security.Cryptography.CngKey]::Import($bobPubKeyBlob, [System.Security.Cryptography.CngKeyBlobFormat]::EccPublicBlob) | |
[Byte[]]$aliceSymKey = $aliceAlgorithm.DeriveKeyMaterial($bobPubKey) | |
[System.Security.Cryptography.ECDiffieHellmanCng]$bobAlgorithm = New-Object System.Security.Cryptography.ECDiffieHellmanCng($bobKey) | |
[System.Security.Cryptography.CngKey]$alicePubKey = [System.Security.Cryptography.CngKey]::Import($alicePubKeyBlob, [System.Security.Cryptography.CngKeyBlobFormat]::EccPublicBlob) | |
[Byte[]]$bobSymKey = $bobAlgorithm.DeriveKeyMaterial($alicePubKey) | |
Write-Host $("Alice has: {0}" -f [Convert]::ToBase64String($aliceSymKey)) | |
Write-Host $("Bob has: {0}" -f [Convert]::ToBase64String($bobSymKey)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have wrapped this into a nice script for execution on two different machines. :)
https://gist.github.com/ciis0/d631e5526fab765ab1bc99a5467d05d2