Hi Peter,
1-
KeysI used 2 pub keys file; one to encrypt the file content and other one to encrypt the file (You can find them in the pub.rar zip)
pub.rarpub_hrn_key.pkr - to encrypt the part of the content of the file.
pub_file_key.pkr - to encrypt the file itself.
and respective pvt key files.
pvt.rarpvt_hrn_key.skr - to decrypt the part of the content of the file.
pvt_file_key.skr - to decrypt the file itself.
2-3.
Windows.ord and
Linux.ord - Note that the content of the 2 files are not equal.
windows.ord were created before moving the code base to Linux.
Linux.ord were created after moving to linux. But I can decrypt the Windows.ord without any issues.
4.
Encryption happen in JAVACode snip that I use to encrypt the part of the file contentprivate String encryptHrn(String content) {
String encHrn = null;
String pathTopublicKey = getPathToHrnKeyFile();
try {
PGPLib pgp = new PGPLib();
InputStream keyFile = new FileInputStream(new File(pathTopublicKey));
ByteArrayInputStream data = new ByteArrayInputStream(content.getBytes());
ByteArrayOutputStream encData = new ByteArrayOutputStream();
pgp.encryptStream(data, "lol.temp", keyFile, encData, true, true);
encHrn = encData.toString();
encHrn=encHrn.replace("-----BEGIN PGP MESSAGE-----", "");
encHrn=encHrn.replace("Version: BCPG v1.45", "");
encHrn=encHrn.replace("-----END PGP MESSAGE-----", "");
encHrn=encHrn.replace("\r\n", "");
} catch (FileNotFoundException fnex) {
fnex.printStackTrace();
} catch (PGPException pgpex) {
pgpex.printStackTrace();
} catch (IOException ioex) {
ioex.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
return encHrn;
}
File encryption public void encryptFile(String sourceFile, String encFile) {
String pathTopublicKey = getPathToFileKeyFile();
String sFile = instanceRoot + File.separator + sourceFile;
String dFile = instanceRoot + File.separator + encFile;
try {
PGPLib pgp = new PGPLib();
InputStream fs = new FileInputStream(new File(pathTopublicKey));
pgp.encryptFile(sFile, fs, dFile, true, true);
} catch (PGPException pgpex) {
pgpex.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Decryption happen in .NETDecrypt file and content main flowDecryptFile(sourceFilePath, destFileName, tempFolderPath);
FileStream finalFile = fm.CreateFile(destinationPath);
//Open the temp file to decrypt HRN
StreamReader sr = new StreamReader(tempFolderPath + "\\" + destFileName);
StreamWriter sw = new StreamWriter(finalFile);
using (sr)
{
while (!sr.EndOfStream)
{
content = new StringBuilder();
string[] rs = sr.ReadLine().Split(',');
string encHrn = rs[1];
string hrn = DecryptHN(encHrn);
content.Append(rs[0] + "," + hrn + "," + rs[2] + "," + rs[3] + "," + rs[4] + "," + rs[5] + "," + rs[6] + "," + rs[7]);
fm.AppendFile(sw, content.ToString());
}
sw.Close();
sw.Dispose();
}
fm.DeleteFile(tempFolderPath + "\\" + destFileName);
}
File decryption Note that all the paths are correctly set to files without any issues.
pvtPassword = "E4T@%^&*";public String DecryptFile(string sourceFile, string destinationFileName, string destinationFolder)
{
string originalFileName = string.Empty;
string destinationPath = destinationFolder + "\\" + destinationFileName;
try
{
pgp = new PGPLib();
originalFileName = pgp.DecryptFile(sourceFile, ApplicationPath.KeyFilePath, pvtPassword, destinationPath);
}
catch (Exception ex)
{
throw new PGPException(ex.Message, ex);
}
return originalFileName;
}
Decrypt file content public string DecryptHN(string hn)
{
string localHn = string.Empty;
try
{
pgp = new PGPLib();
fm = new FileManager();
localHn = pgp.DecryptString(hn, fm.GetHrnKeyFile(), pvtPassword);
}
catch (Exception ex)
{
throw new PGPException(ex.Message, ex);
}
return localHn;
}
I Also attached a sample file at the state of as soon as it been decrypted ( before decrypt the content) [
After_decrypt_the_file.ord]
Please do let me know where is the problem lies relating to this issue.
Thanks in advance for your kind co-operation.
Thx & BR,
Ranga