2

This post is similar to an earlier post about preventing the corruption of PGP binary files when transferring those files to an FTP server using C# (http://stackoverflow.com/questions/7353993/ftp-changing-pgp-file-during-transfer-in-c-sharp), though I'm asking a different question.

Summary:

I've fixed the source of the PGP file corruption by text-armoring all of my PGP encrypted files; however, I have a bunch of PGP binary files that were encrypted and uploaded to my FTP server prior to implementing this fix. Knowing the code used to upload the files to the FTP server and the software used to manage the FTP server, is it possible to fix the corrupted PGP binary files so that they can be decrypted and recovered?

Details: 1) I have PGP encrypted files that were encrypted using Gpg4Win that are not text-armored (they are binary files) that were uploaded from an IIS 6.0 web-server using VB .NET code (included below) to a CoreFTP server.

2) I do not have unencrypted copies of these files. They were encrypted in memory on the web-server before being uploaded to the CoreFTP server. Thus, I need to decrypt the binary PGP files, otherwise the data in the files will be lost.

3) The binary in the PGP files has been corrupted such that, even though I have the correct PGP private key, I cannot decrypt the files in Gpg4Win. Gpg4Win is not able to find / read the PGP data in the encrypted binary files.

4) I am able to successfully decrypt more recent PGP encrypted files that were text-armored (the binary data was stored in base64 notation) before uploading to the CoreFTP server. Therefore, the decryption problem is most likely due to file corruption rather than any issue with Gpg4Win or my PGP private / public key pair.

5) Several binary file recovery programs that I've tried to use on the PGP binary files say that they cannot find the file data and are unable to fix the binary file corruption. Or, they do not make any alteration to the binary data contained in the PGP binary files.

VB .net code used to upload PGP binary files:

Public Function UploadFile(ByVal localFileName As String, ByVal FTPFilename As String, ByVal UseBinary As Boolean, ByVal uniqueName As Boolean, ByRef StatusDescription As String) As FtpStatusCode
    Dim request As FtpWebRequest = CType(FtpWebRequest.Create(FTPFilename), FtpWebRequest)
    request.Credentials = New NetworkCredential(Username, Password)

    If uniqueName Then
        request.Method = WebRequestMethods.Ftp.UploadFileWithUniqueName
    Else
        request.Method = WebRequestMethods.Ftp.UploadFile
    End If
    request.UseBinary = UseBinary

    Dim ff As New FileInfo(localFileName)

    Dim fileContents(Convert.ToInt32(ff.Length)) As Byte

    Using fr As FileStream = ff.OpenRead
        fr.Read(fileContents, 0, fileContents.Length)
    End Using

    Using writer As Stream = request.GetRequestStream
        writer.Write(fileContents, 0, fileContents.Length)
    End Using
    Dim response As FtpWebResponse = CType(request.GetResponse, FtpWebResponse)
    StatusDescription = response.StatusDescription

    Return response.StatusCode
End Function

For my FTP server I'm using the latest version of CoreFTP for Windows.

When responding to the FTP LIST command, CoreFTP returns the file information in Unix format (rather than the MS-DOS format), so I'm wondering if the binary corruption was the result of transferring a binary file from a Windows server that uses MS-DOS formatting for binary files to an FTP server that uses a Unix format. However, I have not experienced any issues opening / reading non-PGP binary files uploaded from my web-server to the CoreFTP server.

Thank you! Isaac

1 Answers1

-1

Looks like your binary files were transmitted in text mode, which translated line endings and probably other non-ascii characters. And, the corruption most likely is not reversible.

Nickolay Olshevsky
  • 13,706
  • 1
  • 34
  • 48