powershell - encrypt strings with public / private keys - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Thread Tools Display Modes
Old 04-02-2014, 05:13 PM   #1 (permalink)
It's all just 1s and 0s
office politics's Avatar
Join Date: Jan 2004
Location: in the lab
Posts: 6,555
Send a message via MSN to office politics
Default powershell - encrypt strings with public / private keys

I found some code to do this. However, it requires the cert to be installed inside the certificate stores in windows. Does anyone know of a way to do the same thing with keys that are strings. This should avoid the need to install the cert on every machine.

Aperture Science Blog - Blog - Encrypting a string using certificates and*PowerShell

Function encrypt-envelope ($unprotectedcontent, $cert)


            [System.Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null

            $utf8content = [Text.Encoding]::UTF8.GetBytes($unprotectedcontent)

            $content = New-Object Security.Cryptography.Pkcs.ContentInfo `

                    -argumentList (,$utf8content)

            $env = New-Object Security.Cryptography.Pkcs.EnvelopedCms $content

            $recpient = (New-Object System.Security.Cryptography.Pkcs.CmsRecipient($cert))


            $base64string = [Convert]::ToBase64String($env.Encode())

            return $base64string


function decrypt-envelope ($base64string)


            [System.Reflection.Assembly]::LoadWithPartialName("System.Security") | Out-Null

            $content = [Convert]::FromBase64String($base64string)


            $env = New-Object Security.Cryptography.Pkcs.EnvelopedCms




            $utf8content = [text.encoding]::UTF8.getstring($env.ContentInfo.Content)

            return $utf8content

office politics is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sony vaio keys acting like function keys maltal77 Laptops and Notebooks 4 07-13-2011 11:44 PM
Improve Firefox Private Browsing With Private Browsing Window Add-on Osiris Tips, Tricks & Tutorials 0 01-23-2010 08:56 PM
Private Browsing Not So Private After All Osiris Internet Software and Browsers 6 01-10-2009 07:32 AM
An odd question, about keyboards with "extra keys," no I don't mean those media keys. Johnathan System Upgrades 4 01-06-2008 11:56 AM

Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 02:03 AM.

Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2019, vBulletin Solutions, Inc.