Solved

wrapping gpg in vb.net to decrypt files

Posted on 2009-05-18
4
1,208 Views
Last Modified: 2012-05-07
I am receiving files encrypted using gpg. I have set Gnupg for Windows to work with a passphrase. How can I use vb.net 2008 to decrypt a whole folder of files? Anyone have a sample? Thanks.
0
Comment
Question by:jwagman
  • 3
4 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24416517
I use this in several apps every day.  I run it as a process inside vb.net.  For your scenario just loop through each file and run my code below.
      '*** decrypt - start

      Dim executestring As String = String.Format("""{0}"" --decrypt-files ""{1}""", gpgpath, tempsourcepath)

      Dim psi As New  _

        System.Diagnostics.ProcessStartInfo(executestring)

      psi.RedirectStandardOutput = True

      psi.WindowStyle = ProcessWindowStyle.Hidden

      psi.UseShellExecute = False
 

      Dim decrypt As System.Diagnostics.Process

      decrypt = System.Diagnostics.Process.Start(psi)

      Dim myOutput As System.IO.StreamReader = decrypt.StandardOutput

      decrypt.WaitForExit(20000)

      If decrypt.HasExited Then

        Dim output As String = myOutput.ReadToEnd

        Debug.WriteLine(output)

      End If

      '*** decrypt - end

Open in new window

0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24416527
Alternatively here is a .net wrapper for gpg.
http://aspalliance.com/748
0
 

Author Comment

by:jwagman
ID: 24416547
Don't I need to include the passphrase as one of the args to process?
0
 
LVL 9

Accepted Solution

by:
cdaly33 earned 500 total points
ID: 24416611
Yes, the gpg documentation has the parameter for passing the passphrase.  I'm not sure off the top of head what arg name it uses.

For you:
      Dim executestring As String = String.Format("""{0}"" --decrypt-files ""{1}""", gpgpath, tempsourcepath)

Becomes:
      Dim executestring As String = String.Format("""{0}"" --decrypt-files ""{1}"" --argnameforpassphrase passphrase", gpgpath, tempsourcepath)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now