How to encrypt the data using script in ssis

  • Hi,

    I am trying to encrypt the flat file data through vb.net code it is not encrypting as well as not giving error. But if i do through cmd it is encrypting. My code is this

    Variable i declared in variable section and calling

    GPGExecutable=C:\\Program Files\\GNU\\GnuPG\\gpg.exe

    HomeDirectory=C:\\Documents and Settings\\1089417\\Application Data\\gnupg

    recipient=abcd

    Public Sub Main()

    Dim vGPGExecutable As Variables

    Dts.VariableDispenser.LockOneForRead("GPGExecutable", vGPGExecutable)

    Dim gpgExecutable As String

    gpgExecutable = vGPGExecutable("GPGExecutable").Value.ToString

    vGPGExecutable.Unlock()

    Dim vHomeDir As Variables

    Dts.VariableDispenser.LockOneForRead("HomeDirectory", vHomeDir)

    Dim HomeDir As String

    HomeDir = vHomeDir("HomeDirectory").Value.ToString

    vHomeDir.Unlock()

    Dim vPassPhrase As Variables

    Dts.VariableDispenser.LockOneForRead("recipient", vPassPhrase)

    Dim recipient As String = vPassPhrase("recipient").Value.ToString

    vPassPhrase.Unlock()

    Dim outputFile As String = "C:\\Documents and Settings\\1089417\Desktop\\Encrypt.txt"

    Dim inputfile As String = Dts.Connections("VCF").ConnectionString

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

    Dim gpgOptions As String

    Dim optionsBuilder As StringBuilder = New StringBuilder()

    optionsBuilder.Append("--homedir ")

    optionsBuilder.Append(HomeDir)

    optionsBuilder.Append(" --yes --batch --armor --recipient ")

    optionsBuilder.Append(recipient)

    optionsBuilder.Append(" --no-verbose --output ")

    optionsBuilder.Append(outputFile)

    optionsBuilder.Append(" --always-trust")

    optionsBuilder.Append(" --encrypt ")

    optionsBuilder.Append(inputfile)

    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

    process.Start()

    streamWriter = process.StandardInput

    streamReader = process.StandardOutput

    err = process.StandardError

    streamWriter.Close()

    'System.Windows.Forms.MessageBox.Show(result)

    Else

    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

    logfile.Close()

    End If

    End Sub

    Can you please help me what is the mistake in my code ASAP.

    Thanks,

    jagadeesh

  • If you are looking for easier encryption alternative and can use third-party solution, check the commercial CozyRoc OpenPGP Task.

    ---
    SSIS Tasks Components Scripts Services | http://www.cozyroc.com/

  • Hi,

    Actually i want sample code for that because i want to know what mistake i did in that code. If you know the url or if you find the mistake in that code can you please help me.

    Thanks,

    Jagadeesh

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply