using System; using System.Data; using System.Linq; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; using Payroll.Service; //using Starksoft.Cryptography.OpenPGP; using System.IO; namespace HRM.DA { public class PGPEncryptionService : ServiceTemplate, IPGPEncryptionService { //private GnuPG gpg = new GnuPG(); private string appPath; private string keyUserId; #region Constructors public PGPEncryptionService() { //this.appPath = Ease.Core.Utility.ConfigUtility.GetAppSettings("GPGPath"); //this.keyUserId = Ease.Core.Utility.ConfigUtility.GetAppSettings("PGPKeyUserID"); } #endregion protected override T CreateObject(DataReader oReader) { PGPEncryption pGPEncryption = new PGPEncryption(); return pGPEncryption as T; } #region Public Methods //public FileInfo EncryptFile(string sourceFile, string encryptedFile) //{ // // check parameters // if (string.IsNullOrEmpty(keyUserId)) // throw new ArgumentException("keyUserId parameter is either empty or null", "keyUserId"); // if (string.IsNullOrEmpty(sourceFile)) // throw new ArgumentException("sourceFile parameter is either empty or null", "sourceFile"); // if (string.IsNullOrEmpty(encryptedFile)) // throw new ArgumentException("encryptedFile parameter is either empty or null", "encryptedFile"); // // Create streams - for each of the unencrypted source file and decrypted destination file // using (Stream sourceFileStream = new FileStream(sourceFile, FileMode.Open)) // { // using (Stream encryptedFileStream = new FileStream(encryptedFile, FileMode.Create)) // { // // Specify the directory containing gpg.exe (not sure why). // gpg.BinaryPath = Path.GetDirectoryName(appPath); // gpg.Recipient = keyUserId; // // Perform encryption // gpg.Encrypt(sourceFileStream, encryptedFileStream); // return new FileInfo(encryptedFile); // } // } //} //public FileInfo DecryptFile(string passPhase, string encryptedSourceFile, string decryptedFile) //{ // // check parameters // if (string.IsNullOrEmpty(encryptedSourceFile)) // throw new ArgumentException("encryptedSourceFile parameter is either empty or null", "encryptedSourceFile"); // if (string.IsNullOrEmpty(decryptedFile)) // throw new ArgumentException("decryptedFile parameter is either empty or null", "decryptedFile"); // using (FileStream encryptedSourceFileStream = new FileStream(encryptedSourceFile, FileMode.Open)) // { // // make sure the stream is at the start. // encryptedSourceFileStream.Position = 0; // using (FileStream decryptedFileStream = new FileStream(decryptedFile, FileMode.Create)) // { // // Specify the directory containing gpg.exe (again, not sure why). // //gpg.Passphrase = passPhase; // gpg.BinaryPath = Path.GetDirectoryName(appPath); // // Decrypt // gpg.Decrypt(encryptedSourceFileStream, decryptedFileStream); // } // } // return new FileInfo(decryptedFile); //} #endregion } }