Regarding Encryption through code using gpg

Jagadeesh Bantrotu Jagadeesh.Bantrotu at
Tue Dec 8 14:22:54 CET 2009


I am trying to encrypt the file using code but the data is not encrypting and it is not giving error. But if I do from cmd prompt the file is encrypted.
Can you tell me what mistake I did in my code? I first used gpg version 1.4.9 with this version the code was not executed after that I tried with gpg version 1.2.0 but no use. Any one can help me ASAP.

  Dim vGPGExecutable As Variables
        Dts.VariableDispenser.LockOneForRead("GPGExecutable", vGPGExecutable)
        Dim gpgExecutable As String
        gpgExecutable = vGPGExecutable("GPGExecutable").Value.ToString

        Dim vHomeDir As Variables
        Dts.VariableDispenser.LockOneForRead("HomeDirectory", vHomeDir)
        Dim HomeDir As String
        HomeDir = vHomeDir("HomeDirectory").Value.ToString

        Dim vPassPhrase As Variables
        Dts.VariableDispenser.LockOneForRead("recipient", vPassPhrase)
        Dim recipient As String = vPassPhrase("recipient").Value.ToString

        Dim outputFile As String = Dts.Connections("Encrypt").ConnectionString
        Dim inputfile As String = Dts.Connections("File").ConnectionString

        If System.IO.File.Exists(inputfile) = True Then

            Dim gpgOptions As String

            Dim optionsBuilder As StringBuilder = New StringBuilder()
            optionsBuilder.Append("--homedir ")
            optionsBuilder.Append(" --yes --batch --armor --recipient ")
            optionsBuilder.Append(" --no-verbose --output ")
            optionsBuilder.Append(" --always-trust")
            optionsBuilder.Append(" --encrypt ")

            gpgOptions = optionsBuilder.ToString()

            Dim process As Process = New Process()
            Dim streamWriter As StreamWriter
            Dim streamReader As StreamReader
            Dim err As StreamReader

            Dim prStartInfo As ProcessStartInfo = New ProcessStartInfo(gpgExecutable, gpgOptions)
            prStartInfo.UseShellExecute = False
            prStartInfo.RedirectStandardInput = True
            prStartInfo.RedirectStandardOutput = True
            prStartInfo.RedirectStandardError = True
            prStartInfo.CreateNoWindow = True
            process.StartInfo = prStartInfo
            streamWriter = process.StandardInput
            streamReader = process.StandardOutput
            err = process.StandardError

            Dim logConstr As String
            logConstr = Dts.Connections("Log File Connection String").ConnectionString
            Dim logfile As StreamWriter = New StreamWriter(logConstr, False)
            logfile.WriteLine("Fail to Find Records File to be Encrypted.")
            Dts.TaskResult = Dts.Results.Failure

        End If

Jagadeesh B


This email may contain confidential information and is intended only for the use of the specific individual(s) to which it is addressed. If you are not the intended recipient of this email, you are hereby notified that any unauthorized use, dissemination or copying of this email or the information contained in it or attached to it is strictly prohibited. If you received this message in error, please immediately notify the sender at Infotech or Mail.Admin at and delete the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20091208/4f20e990/attachment-0001.htm>

More information about the Gnupg-users mailing list