web stats
Mirth Community - View Single Post - Read encrypted file
View Single Post
  #1  
Old 06-20-2019, 01:09 AM
lam0620 lam0620 is offline
What's HL7?
 
Join Date: Jun 2019
Posts: 1
lam0620 is on a distinguished road
Default Read encrypted file

Hi,

I'd like read by JavaScript Reader the files that encrypted by C# as below code. I'm newbe Mirth Connect.
I really appreciate if you could help me.


HTML Code:
private static void EncryptFile(string inputFile, string outputFile, string skey)
{
    try
    {
        using (RijndaelManaged aes = new RijndaelManaged())
        {
            byte[] key = ASCIIEncoding.UTF8.GetBytes(skey);

            /* This is for demostrating purposes only.
             * Ideally you will want the IV key to be different from your key and you should always generate a new one for each encryption in other to achieve maximum security*/
            byte[] IV = ASCIIEncoding.UTF8.GetBytes(skey);

            using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
            {
                using (ICryptoTransform encryptor = aes.CreateEncryptor(key, IV))
                {
                    using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                    {
                        using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
                        {
                            int data;
                            while ((data = fsIn.ReadByte()) != -1)
                            {
                                cs.WriteByte((byte)data);
                            }
                        }
                    }
                }
            }
        }
    }
    catch (Exception ex)
    {
        // failed to encrypt file
    }
}
Reply With Quote